Right now you're mutating a prop which is not something you should be doing according the react docs, your easiest approach will be passing a callback that does the same action in your that your sidebar onClick is doing, but as a prop, and using the setStatus function, instead of doing the change manually, something like this:
<Sidebar show={status} onSidebarClick={() => setStatus(!status)} />
And in your sidebar component you just need to do this:
const Sidebar = ({ show, onSidebarClick }) => {
// Your code
return (
{/* Rest of your JSX */}
<button onClick={onSidebarClick}>Back</button>
)
}
You should pass the callback function from the parent and use the setStatus function to perform the change. Do not try to do the change by yourself without the setStatus function.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…