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.

getState for non-redux version

See original GitHub issue

There is no getState for createGlobalState (the one you use without redux).

So its not possible to get the state inside a non-react functional component without write this hack.

    var state;
    setGlobalState('login', v => {
      state = v;
      return v;
    });

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:17 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
dai-shicommented, Jun 7, 2019

Anyway, let’s merge #18.

1reaction
dai-shicommented, Jun 7, 2019

In short, I would only export keyed API. If someone really need a whole object, one can do the following:

const getWholeGlobalState = () => {
  const obj = {};
  Object.keys(initialState).forEach((key) => {
    obj[key] = getGlobalState(key);
  });
  return obj;
};

This is a bit of extra work, and one should use getGlobalState(key) whenever possible.


What’s important here is that the fact that this library uses observedBits is an implementation detail, and React may drop this API at any time. If it’s simply dropped, I would change the implementation to use multiple contexts and the getWholeGlobalState might be implemented just like the above. I believe that exporting getWholeGlobalState encourages the misuse of it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I get an immutable version of an object from store ...
I'm using react-redux for a project I'm working on. I noticed that when I grab an object from my store and edit it,...
Read more >
Build Yourself a Redux - The Zapier Engineering Blog
Redux is a simple library that helps you manage the state of your JavaScript app. Despite that simplicity, it's easy to fall down...
Read more >
Redux-Observable will solve your state problems. - ITNEXT
To do so, you're almost always going to be calling into their non-Redux ... Redux-Observable, prior to version 1, did not handle immediate...
Read more >
npr/redux-external-dispatchers - GitHub
A Redux store enhancer to let non-Redux pieces of your application dispatch actions into Redux without also having access to Redux state.
Read more >
redux-selector-subscribe - npm
Latest version: 1.0.0, last published: 5 years ago. ... still use cases for notifying your non-Redux code about an update to Redux state....
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