At first you should create constructor like this
constructor(props) {
super(props);
this.state = {
close: true,
};
}
yourFunction = () => {
this.setState({
close: !this.state.close,
});
};
then use this like
render() {
const {close} = this.state;
return (
this.yourFunction()}>
)
}
}
Please give better solutions