A deep dive on forms with modern React
React 19 introduces terrific primitives for building great forms. Let's dive deep on forms for the web with React.

Ricky Hanlon posted on Bluesky:
what's wrong with this code:
if (props.wrap) {return <Wrapper>{children}</Wrapper>}return children
A lot of people didn't get it right away. In fact, it took me a moment thinking about it as well, but then I replied:
Does it have to do with what happens when the wrap prop changes?
He said "Yes" and I knew for sure what he was talking about.
Have you ever wondered why your React component's state sometimes disappears or resets unexpectedly? Or why two identical components don't share state? React's approach to state is all about where a component sits in the UI tree, not just what it is. This means that state is preserved as long as the same component is rendered at the same position—but if you swap components, change their keys, or move them around, React may reset their state.
A common pitfall: toggling between two components (like two players in a scoreboard) using different keys or types will reset their state every time you switch. This is often not what you want, especially if you expect the UI to "remember" previous input or progress. The React docs show how this can trip you up, and why relying on position and keys for state can be sub-optimal if you're not careful.
If you've ever been surprised by disappearing form input or state that doesn't persist the way you expect, this article is for you. It covers:
Curious to learn more and see code examples? Check out the full article: Preserving and Resetting State – React Docs
For Ricky's example specifically, if you want to preserve state while toggling
the wrapper, you need to ensure the component tree structure remains stable. One
way is to always render the Wrapper
, but conditionally apply styling or
behavior:
return ( <Wrapper style={props.wrap ? {} : { display: 'contents' }}> {children} </Wrapper>)
Or, if you want to avoid an extra DOM node when not wrapping, you can use a key to intentionally reset state, or lift state up to a parent component so it isn't lost when the tree changes. The key is to avoid swapping between two different component trees at the same position if you want to preserve state.
But really, you should just read the whole article.
Delivered straight to your inbox.
React 19 introduces terrific primitives for building great forms. Let's dive deep on forms for the web with React.
Is your app as fast as you think it is for your users?
React Server Components are going to improve the way we build web applications in a huge way... Once we nail the abstractions...
How React's new model lets you build interactive, data-rich UIs without the pain of old-school script tags and prop drilling.