0

This is React's explanation for use of Context

Context is designed to share data that can be considered “global” for a tree of React components, such as the current authenticated user, theme, or preferred language.

While this holds good for React components, is it practical to consider using context to share data between React containers as well? Is there an alternative for Redux or MobX, inbuilt in React?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Edison D'souza
  • 4,551
  • 5
  • 28
  • 39
  • 1
    What do you mean? Container components are still components. – Estus Flask Apr 25 '19 at 07:42
  • you can use the redux-store with selector – Angelotti Apr 25 '19 at 07:50
  • Components share data through props and are nested and we can use context. What about data between screens which gets rendered when `navigate` is called. Is it practical to use context in that case as well. Or is there an alternative? – Edison D'souza Apr 25 '19 at 07:52
  • @EdisonD'souza I'm not sure what you mean by `navigate`. If you have specific case in mind, consider providing an example in the question. Any way, both Redux and Mobx use context API internally. If you want to do this with context alone, you will have to implement some of their functionality. – Estus Flask Apr 25 '19 at 08:00
  • Possible duplicate of https://stackoverflow.com/questions/49568073/react-context-vs-react-redux-when-should-i-use-each-one/49569183#49569183 – Shubham Khatri Apr 25 '19 at 09:13

1 Answers1

1

React Context can be used in place of something like Redux or Flux but you might want to look into using React Context for low-frequency updates (e.g. theme changes, user authentication) but not use it for the general state management of your application.

This is what Sebastian has to say regarding this....who is greatly involved with React development.

My personal summary is that new context is ready to be used for low frequency unlikely updates (like locale/theme). It’s also good to use it in the same way as old context was used. I.e. for static values and then propagate updates through subscriptions. It’s not ready to be used as a replacement for all Flux-like state propagation. --- Sebastian Markbage

https://github.com/reduxjs/react-redux/issues/1177

Hope this helps.

Hemant Parashar
  • 3,684
  • 2
  • 16
  • 23