-
Notifications
You must be signed in to change notification settings - Fork 103
How to pass values from redux store to useCallback as dependency arguments #36
Comments
What do you mean by this? Are you updating some piece of UI? Or another variable in your component? |
@ianobermiller |
@ianobermiller
|
@ianobermiller In other words I kinda don't understand the situation we limiting to read store updates by the arguments which might not belong to the store at all. I was thinking about the store like an observable collection to which we subscribe for updates receiving, but seems like now it is not. |
Can you create a simple codesandbox demonstrating the issue? Another way to explain this that might help is showing how you would solve this with react-redux. |
@ianobermiller |
I'm still not really sure what you want to accomplish. Copying from Input.tsx: const [localStateValue, setLocalStateValue] = useState("");
useMappedState(
useCallback(
reduxStoreState => {
const reduxStoreValue = reduxStoreState.processedValue;
if (localStateValue.value !== reduxStoreValue.value) {
setLocalStateValue(reduxStoreValue);
}
},
[localStateValue.value] // I wish I can have an access to reduxStoreState.processedValue here
//to pass it's value as a dependency
)
);
const localStateValue = useMappedState(useCallback(
reduxStoreState => reduxStoreState.processedValue,
[],
)); |
It doesn't really make sense to do this -- the entire point of the callback is to select something from the store, so how could the callback itself be based on the store values? You can certainly select things from the store with I'm going to close right now, but I will reopen if our discussion turns up something actionable. |
Hi Ian, thanks! Your example is working well, I tried similar thing before, but |
@ianobermiller I have updated, the previous example, just to clarify that situation. |
Sounds like you may be referring to top-down data flow, which this hook does not implement: https://github.com/facebookincubator/redux-react-hook#how-does-this-compare-to-react-redux |
Hi Lads,
Sorry, if this is wrong place to ask the question, please point me to the correct one.
In my case I end up with situation when I have to update my property depend on the changes happened to one of the store values. Was looking through the tutorial and didn't find any solutions for this kind of cases.
After digging a little bit deeper into original redux api I found that I can subscribe to the store directly and getState() outside of useCallback, read the necessary value and provide it as a useCallback dependency argument. But in that case, seems like it makes the useMappedState() redundant...
Could you please help me to find the right way to sort this?
The text was updated successfully, but these errors were encountered: