by mvdtnz · 1y ago · 0 comments
My sense is that in React, the complexity comes from the management of minimizing the "blast radius" of state changes to prevent over-renders. So there are a lot of different approaches and ways that folks have cleverly engineered to solve this problem, but none of them feel as simple as say Pinia on Vue, for example.
You have your app state in an object/class, and components automatically rerender when the part of the store changes that they access during render.
class Store {
counter = 0
constructor() { makeAutoObservable(this) }
increment() { this.counter++ }
}
const Component = observer(() {
const store = useStore()
const click = () => store.increment())
return <button onClick={click}>{store.counter}</button>
})
It has a very light set of idiosyncrasies for what it gives you unlike, say, redux.https://github.com/Facepunch/react-class-model (note: context is not required)
It has a lot of expressivity but is incredibly brittle and dangerous.
Angular too many digest cycles anyone?