Does a child component unmount in react when parent rerenders?

Viewed 1241

Hi i observed a strange thing during one of my projects, which i think changes my understanding of th react renders, just what to confirm if i am right...,

i am passing function into useState hook to set initial state, in a child component

const [state,setState] = useState(()=>initialStateFn());

my understanding is that initialStateFn will run on every mount of the component, and i was of the belief that child would remount when parent component rerenders causing the initialStateFn to run again, but it seems though the parent rerenders the initialStateFn does not run, it is as if child was not unmounted..., so wanted some clarity here, about what causes a child to remount

0 Answers
Related