1
Let’s say I have a parent component:
import React from 'react';
import style from './style.less';
export default class Wrapper extends Component {
this.state = {
active: false
}
render() {
return (
<section className={style.wrapper}>
<h2>{props.text}</h2>
<div className={style.main}>
<Button isCentered={true} text="Precisa de alguma ajuda?" bgColor="#673ab7" color="white" />
</div>
</section>
)
}
);
export default Wrapper;
And a child component:
import React from 'react';
import style from './style.less';
const Button = (props) => (
<div class={style.button} style={{textAlign: `${props.isCentered ? "center" : "left"}`}}>
<a onClick={console.log("Clicou!")} style={{backgroundColor: `${props.bgColor}`, color: `${props.color}`}} class={style.a}>{props.text}</a>
</div>
);
export default Button;
Man App.js
:
import { react, Component } from 'react';
import Header from './Wraper';
export default class App extends Component {
constructor() {
super();
}
render() {
return (
<div id="app">
<Wraper text="Lorem Ipsum" />
</div>
);
}
}
How can I change the state active
Component Wrapper
for true
the moment I click on the child component Button
?