withGlobal cannot find the global state in React Native.
See original GitHub issueHi, im trying to use reactn on react native but im getting this issue when using the withGlobal HOC
import React, {withGlobal} from 'reactn'
const GroupSelector = () => {
return (
...
);
}
export default withGlobal(
global => ({
groups: global.groups
}),
)(GroupSelector);
Any assistance you can provide would be greatly appreciated
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Global state in React Native - Stack Overflow
I usually create a global.js containing: module.exports = { screen1: null, };. And get the value of the state on the screen
Read more >Global state management in React with global variables and ...
So the problem here is, when one component updates a global state other components sharing that global state doesn't know, the only component ......
Read more >Using React Global State with Hooks and Context | Savas Labs
Set and manage global state for a small React Native app built from functional components, without using Redux or Mobx.
Read more >React v18.0 – React Blog
Note for React Native users: React 18 will ship in React Native with the New React Native Architecture. For more information, see the...
Read more >Building ReactN — An extension of React that includes global ...
There is no reason a global state package should require so much ... appear to be designed with global state management in mind,...
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
This is fixed and will be deploying a few moments.
Technical Details
The issue is that a missing Context in React-for-web returns undefined (falsey), but a missing Context in React Native returns an empty object (truthy). The check has been changed from truthy/falsey to
this.context instanceof GlobalStateManager
.Breaking Change
As a part of this fix, I’ve made a breaking change that should be have been included in
2.0.0
, which is why I’m not bumping the major version number.The getter and setter functions previously accepted two parameters: the global state and the HOC’s props.
(global, props) => {}
.Now, they accept three parameters: the global state, the dispatchers for your reducers, and the HOC’s props.
(global, dispatch, props) => {}
.If you are relying on
props
as your second parameter, be sure to change it to the third parameter by addingdispatch
as the second.before:
after:
Thanks @CharlesStover