Managing Complex UI Component State
Published ....
Last modified ....
Share this post on BlueskySee discussion on Bluesky
Managing state in React is difficult. While many suggest that lifting state up to the highest level of the app, and frequently even outside of the component tree, most apps aren't that simple.
One case where this becomes complicated is when app authors need to interact with complex UI components within their application. I internally wrestle with this concept frequently as I build these UI components everyday at work.
One of the most recent cases where I am running into this is our new carousel component which I started work on about 6 months ago as of the time of writing this blog post. This component is perhaps the most complicated UI component we have at Wayfair.
It manages quite a bit of internal state, ranging from actual React state to many references to the rendered dom nodes as well. The problem here is that we also want end users (app developers) the ability to control the carousel from their business logic.
We started with the concept that render props and prop getters would be sufficient to allow end users to control the carousel, however over the months of development, we realized that many (maybe 90%) of frontend developers at Wayfair (and really anywhere) don't want to manage a lot of state and helpers that comes with a render prop.
So we mostly scrapped the render prop pattern on the carousel
[1]Jump to footnote