How can I pass function with React Hooks? I've used useCallback, but it shows an error that it is not a function.
In class component I was doing it like this:
hidePopUp = (event) => {
event.preventDefault();
this.setState({
popup: !this.state.popup
})
}
Then I was passing function:
<Popup hidePopUp={this.hidePopUp}/>
That's my problem with Hooks:
const hidePopup = useCallback(
(event) => {
event.preventDefault();
setPopup(!popup);
}, []
);
<Popup hidePopup={() => hidePopup}/>
And this is my button in Popup component:
<button onClick={(event)=>this.props.hidePopUp(event)}></button>