class Func1 extends Component {
constructor(props) {
super(props);
this.state = {
visible: false
}
openForm = (event) => {
this.setState({
visible: true /* <= присвоили true*/
});
}
}
}
class Func2 extends Component {
constructor(props) {
super(props);
this.state = {
visible: /* вот сюда */
}
}
}
class FormWidget extends Component {
state={
isFormVisible: false,
};
handleButtonClick = () => {
this.setState(prevState => ({
isFormVisible: !prevState.isFormVisible,
}));
}
render() {
const { isFormVisible } = this.state;
const buttonText = isFormVisible ? 'Hide form' : 'Show form';
return (
<Wrapper>
<Button onClick={this.handleButtonClick}>
{buttonText}
</Button>
<Form isVisible={isFormVisible} />
</Wrapper>
)
}
}