Giter Club home page Giter Club logo

Comments (11)

sean-gilmore avatar sean-gilmore commented on June 26, 2024 1

All good! Will see how I go working on a fix. Enjoy the holiday 😄 🏖

from redux-subspace.

mpeyper avatar mpeyper commented on June 26, 2024

Yeah, this should work. I'll take a closer look when I get a chance. If you want to speed me up, set up a repo, codesandbox or unit test in this repo that replicates the issue.

from redux-subspace.

sean-gilmore avatar sean-gilmore commented on June 26, 2024

Hey @mpeyper, haven't had a chance to set up a codesandbox just yet, but I believe this is the same issue as described in the redux documentation for the useStore() hook. I believe that you'd need to implement a hook similar to useSelector() that can access the parent store. I'll have a go tomorrow, but it might be a little outside my wheelhouse.

from redux-subspace.

sean-gilmore avatar sean-gilmore commented on June 26, 2024

Hey @mpeyper, I've created an example of the issue in this repo: https://github.com/sean-gilmore/redux-subspace-hooks-example

from redux-subspace.

mpeyper avatar mpeyper commented on June 26, 2024

Thanks. I'm actually on holiday for the next week, but I'll take a look if I have some spare time.

from redux-subspace.

sean-gilmore avatar sean-gilmore commented on June 26, 2024

Hey @mpeyper, I've found a createSelectorHook function in the react-redux project, that seems to allow you to create a new selector hook with a given context. I'm not super familiar with the concept of context in React, but do you think this would be the right avenue to keep investigating?
https://github.com/reduxjs/react-redux/blob/master/src/hooks/useSelector.js

from redux-subspace.

mpeyper avatar mpeyper commented on June 26, 2024

No, unfortunately I do not believe the issue lies in with context the selector is created with. One of the things we do is import the same default context so it's supposed to work out of the box (very few people actually override this with there own context, as far as I'm aware).

I'm a little bit confused why this is even a problem. The parent space functionality is literally just a reference to the original, unmodified store used as the base when creating the subspace, so any selectors, dispatches and subscriptions should work identically to if they were connected from outside the subspace all together (i.e. if you weren't using redux-subspace at all.

from redux-subspace.

mpeyper avatar mpeyper commented on June 26, 2024

Ok, looking more closely at your sandbox, I can see that you are not actually subscribing to the store changes, but rather called parentState.getState() as part of rendering. The lack of any other trigger to cause react to rerender causes the ui to appear to freeze, although the store has actually updated the value.

Here is a fork of your sandbox that shows that if you do subscribe to the store, you get the intended update to the component:

https://codesandbox.io/s/heuristic-carson-pjbte

Another way to have it work is to use the react-redux hooks from a nested component within a ParentSpaceProvider:

https://codesandbox.io/s/magical-roentgen-fup89

Obviously this isn't the code you were expecting to write, and it's possible that the exposed hooks from our API actually don't hold much use but should rather have accompanying useParentDispatch and useParentSelector hooks that use the more primitive useParentSpace hook but also handle the subscription parts more eloquently for you.

from redux-subspace.

sean-gilmore avatar sean-gilmore commented on June 26, 2024

Awesome! Thanks Michael, I'll give these a go tomorrow. Any way that I can send you some beer money for your help?

from redux-subspace.

mpeyper avatar mpeyper commented on June 26, 2024

I'm feeling like we should add the companion hooks to make the hooks we export actually useful. I'm struggling to imagine a use-case where I want a reference to the parent space in my components but not rerender when the parent store updates. Even the react-redux docs suggest the useStore hook should be rarely used.

I'm also thinking that the same reasoning is true for the useSubspace hook and we should also provide companion hooks for that one as well.

I'm a little worried that the solution in the sandbox I linked that mimicked the behaviour by subscribing to the store is a bit naive and the correct implementation will end up looking like a copy of react-redux's useSelector hook.

Any way that I can send you some beer money for your help?

Thanks, but this package is owned by the company I work for, from whom I'm already compensated, so I would not feel comfortable accepting beer money for it.

from redux-subspace.

mpeyper avatar mpeyper commented on June 26, 2024

Closing. Please see #546 for details.

from redux-subspace.

Related Issues (20)

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.