Kent C. Dodds 🌌 @kentcdodds.com · May 19

Do you know the answer to @ricky.fm's question? (No, it's not semicolons 🤭). Let's talk about it on Epic React! www.epicreact.dev/preserving-a...

40 likes 10 replies

?

Replies

Shreyas Mididoddi · May 19

hmmm idk the children gets unnecessary re renders cuz the tree changes whenever the condition changes??

Kent C. Dodds 🌌 · May 19

Original post from @ricky.fm for you to favorite and whatnot bsky.app/profile/rick...

zilahir · May 21

hah i'll add this to my interview questions!

Reiner Leal · May 19

My final answer bsky.app/profile/rein...

Seb ⚛️ ThisWeekInReact.com · May 21

Honestly, I'm not sure why React couldn't support preserving state in this case, considering the Any reason not to support this @ricky.fm @sebmarkbage.calyptus.eu ?

Matija Marohnić · May 21

Unfortunately <Wrapper> often isn't that simple. In my case it's a modal that renders children in a portal, so the provided solution won't quite cut it. But I don't think there's anything necessarily wrong with the logic in the first place, as long as we're being mindful of the consequences.

Matija Marohnić · May 21

return <>{children}</>

Rasmus Schultz · May 20

I recently looked into display:contents and decided not to use it for now caniuse.com/css-display-... I would just toggle a className attribute instead, I think 😌

Musa · May 21

reconciliation? Also, could this be fixed using keys but idk how to implement those for children in this case (just thinkin out loud)

Andrew James · May 19

I ran into this issue for our Modal component. It’s tricky for me to always render the same structure, as the FormProvider (from React Hook Form) is typed to receive the returned values of the useForm hook Is there any way to preserve child state in this case? bsky.app/profile/ajam...