Ways I share data between React components: I prefer: ✅ Read/write to the...
Ways I share data between React components:
I prefer:
✅ Read/write to the URL
✅ Pass values and callback functions via props
✅ Use a library that caches fetched data (react-query/swr/Apollo/etc)
I avoid:
🚩 context
🚩 globals
🚩 cookies/localStorage
🚩 Sharing via the DOM
That said, avoid != never.
For instance, context (or alternatives like Jotai or Zustand) can be useful for stuff that is used everywhere and rarely changes.
Examples:
✅ User info
✅ Feature flags
✅ Global settings like selected language or theme (light vs dark mode)