Is it possible to use state outside of the React context?
See original GitHub issueIn Redux, I can do something like:
import store from "./store";
store.dispatch({ type: "SOME_ACTION" });
const state = store.getState();
in whatever place I want. When using React Context, I’m kinda forced to use it only from within the component. There are ways of creating functions that get reference to dispatch
function but still everything has to be done in the context of Provider.
I would like to use react-tracked
but I guess it’s currently impossible to switch from Redux when someone is using store outside of the React context? Right?
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Use React Context outside of a component : r/reactjs - Reddit
My idea was to update context from my common request handler "services/handleRequest. js" and then watch the context from "app.
Read more >Access React Context outside of render function
I'm creating 2 contexts (one for dispatch and one for state). You would first need to wrap some outer component with the SampleProvider...
Read more >How to use React Context like a pro - Devtrium
Only use React Context if you really need it · Share the authentication state across your app · Share a theme across your...
Read more >Updating React context outside of a component
React context is normally updated inside the React app. Here's a hacky way how I circumvented that restriction in a test file. Table...
Read more >How To Share State Across React Components with Context
React context is flexible enough to use as a centralized state management system for your project, or you can scope it to smaller...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Added: https://react-tracked.js.org/docs/recipes/#usereducer-with-event-listener
You are welcome. Hope you like it!