Data normalization
Some discussions appeared in the Rematch GitHub repository where some folks asked when and how they should save their data inside the store. We suggested the same thing as always: keep it simple.
If you need some local state that is not going to be used anywhere, use React's useState
. If you need some local state that has side effects, you can use libraries that solve this, such as react-query
, or even useEffect
and useState
together. And when you need to fetch some data or store some data that will be used in multiple screens, or you just want to fetch it once and use it anywhere, you can use Rematch with Redux, but always with data normalization.
Going back to the Amazhop application, as you'll remember, our cart state was something like this:
type CartState = { addedIds: Array<string>; quantityById: Record<string, number>; }; const INITIAL_STATE: CartState = { addedIds: [], quantityById...