Parent Component
- Child Component A
- Child Component B
when i change the state of Parent component..
the component A and B renders again with their own state.. which was retained
but i want that when i change the state of Wrapper Component
Compoent A and B restart again as if the website was reloaded.. forgeting about their old state
and reset their to initial state
as if website is just loaded
on the basis of state of Wrapper Component
I expect that when i change the state of Parent Component. the children render again .. forgeting their old state… and render as if website is refreshed on the basis of state of Parent state
2
Answers
can you try to pass state from parent component?
it means your all state will manage in parent
In React, when the key prop of the Component changes, It unmounts the old Component and mounts a new one.
I have used clicked state in the parent component and passed it in the dependency array of useEffect hook, whenever you press the
click
button, clicked state changes, the Parent component will re-render and useEffect toggles the state of key that leads to mount ChildComponent as fresh.You can use as many states in the parent component, and all states in the dependency array of useEffect hook.
Parent Component
Child Component
If you wanna play around with code