Comments (11)
All good! Will see how I go working on a fix. Enjoy the holiday 😄 🏖
from redux-subspace.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Closing. Please see #546 for details.
from redux-subspace.
Related Issues (20)
- @types in redux-subspace-observable dependencies HOT 1
- TypeError: undefined is not an object (evaluating 'store.subspaceOptions') HOT 4
- [redux-subspace] Thunk actions not namespaced HOT 11
- Any ideas on subspacing components with render props? HOT 7
- Removing Subspaced Reducer HOT 3
- TypeError: Object doesn't support property or method 'startsWith' [redux-subspace] HOT 1
- react-redux-subspace support react-redux 7 HOT 2
- [redux-subspace]Being in a subspace, can I dispatch an action to an other one ? HOT 3
- Ability to provide specific enhancer to a subspace HOT 19
- [redux-subspace-saga] Support redux-saga@^1.0.0 HOT 5
- Error on parentSpace HOT 2
- Basic subspace example incorrect in docs HOT 1
- Compatibility issue with react-redux v6 HOT 3
- [redux-subspace] In namespaced reducer, actions should be global by default HOT 1
- Subspaced Saga - React to global action HOT 4
- react-redux-subspace npm audit denial-of-service vulnerability in recompose/node-fetch HOT 1
- Action Required: Fix Renovate Configuration
- Deprecated
- Using a prefilled state with namespaced reducers causes loss of the default store values. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redux-subspace.