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.

withGlobal cannot find the global state in React Native.

See original GitHub issue

Hi, im trying to use reactn on react native but im getting this issue when using the withGlobal HOC

WhatsApp Image 2019-05-17 at 9 40 29 AM

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

github_iconTop GitHub Comments

2reactions
CharlesStovercommented, Jun 1, 2019

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 adding dispatch as the second.

before:

export default withGlobal(
  (global, props) => ({ ... }),
  (setGlobal, props) => ({ ... }),
)(MyComponent);

after:

export default withGlobal(
  (global, dispatch, props) => ({ ... }),
  (setGlobal, dispatch, props) => ({ ... }),
)(MyComponent);
0reactions
BDQcommented, Jun 4, 2019
Read more comments on GitHub >

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

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