question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it possible to use state outside of the React context?

See original GitHub issue

In 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:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dai-shicommented, Dec 19, 2019

You are welcome. Hope you like it!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found