Hi dev,
I'm currently somewhat unhappy with the way that Landscape handles its
state. Here are some of the issues that I'm currently running into.
- Insane prop drilling: Some of the components that we have use
significant swathes of the state (looking at you InviteSearch). This
is necessary, but creating an InviteSearch field deep in the component
tree generally requires adding several props to every single one of
its ancestors. This is a solved problem in React and there's no reason
we have to clutter up our components with a million props.
- State updates are in-place: This is for one a performance issue, as
we could in theory use PureComponent everywhere if we discarded
mutability. For two, it hampers adoption of hooks, as hook
dependencies are generally compared with reference equality.
- Waiting for state to load is a bit odd in places, and oftentimes
abuses the elvis operator heavily in order to account for unloaded
data.
- Poor namespacing and modularisation of updates/api requests/reducers
The canonical solution to all of our problems here is some kind of
state container, such that we could ''teleport''' chunks of state deep
into the component tree. There are a significant number of state
containers for react, so I'll just go over the pros and cons of some
of the ones I'm familiar with. I had a look at recoil, but it looks
too immature for our purposes.
Redux:
Pros:
- Reducer pattern maps quite nicely to the way we get cages over a
subscription
- Tried, tested, not flavor-of-the-month
- Composes well
- Well supported with third-party middleware
Cons:
- Async middleware is strange and complex
- Reducer pattern can be quite verbose for simpler local state
that we don't get from our ship
Zustand:
Pros:
- Colocates the state, write requests and requests in a way that
is very conducive to modularisation
- Actions can be async
- Small, simple, doesn't really add any concepts over and above
vanilla react
- Doesn't need to be used with any particular webframework
Cons:
- Hooks are the only means of consuming state
MobX:
Pros:
- Less boilerplate than redux
- Allows mutable state
- Very usable out of box
- Widely used
- Kinda OOP esque
Cons:
- Kinda OOP esque
- Not very vanilla
Interested to hear everyone's thoughts. Let me know what you think.
——
~hastuc-dibtux
https://urbit.org