I want to set an event on Header when an action happened on {children}, how can i do this
function Basic({ children }) {
return (
<>
<Header/>
{children}
<Footer />
</>
);
}
export default Basic;
I have tried with document event but it didn’t work
{chidren} is an over flow y component and when I scroll on it, I expect event will dispatch to Header
2
Answers
Use React.cloneElement to send data from callback to prop
Create a state at the top level and pass it to children and listen for state change.