Git Product home page Git Product logo

shared-store-hook's People

Contributors

elratondefuego avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

shared-store-hook's Issues

Make compatible with Serverside rendering

Is there a way to make this awesome statemanagement library compatible with SSR?

Now React throws this warning:

Warning: useLayoutEffect does nothing on the server, because its effect cannot be encoded into the server renderer's output format. This will lead to a mismatch between the initial, non-hydrated UI and the intended UI. To avoid this, useLayoutEffect should only be used in components that render exclusively on the client

BTW thx for making a alternative for "use-global-hook" this library is way beter and migrating was quite easy thanks to you.

Prevent possible race condition where a subscribing component could miss its first update

When a new subscribing component calls a shared store hook, the state it will get back is first computed, and then adding this component to the subscribers set is done in a useEffect.

If a state update happens between these two steps (after the return value is computed but before the addition to the subscribers set is performed), the component may get a pre-update state back, and may not be re-rendered on this update.

To avoid this, a useLayoutEffect has to be used in place of the UseEffect, to make sure that the subscription happens before the state change.

Sharing State with other Shared State Hooks

How would you approach modifying the state of one store from another? Is this a sign that the states should be merged into one? Please see a contrived example below (with an obvious misuse of hooks):

const useUser = createSharedStoreHook(...);
const useCart = createSharedStoreHook({
  actions: {
    updateCartBasedOnUserState() {
       // const [userState] = useUser();
       // ...
    }
  },
})

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.