Specify custom dependencies for useObservableSuspense
#53
Replies: 7 comments
-
Looking through the source code, I have a feeling that this boils down to which leads to and in that Although, since it registers changes with regards to the input$ observable, I don't see why it's not updating. |
Beta Was this translation helpful? Give feedback.
-
Actually to add to that, args param itself which could explain why this issue is arising.What actually is happening is that on this line here: the args value is not being passed as a dependency to the useIsomorphicLayoutEffect hook which means no further updates are registered (or what I assume)
|
Beta Was this translation helpful? Give feedback.
-
After adding the following into the useEffect(() => {
setState(resource.read());
}, [resource]); I'm not sure if there are any implications elsewhere of this code, but so far that has solved the issue for me. I updated it on my fork there. Awaiting comment |
Beta Was this translation helpful? Give feedback.
-
If you want to listen to props or states changes, there is a |
Beta Was this translation helpful? Give feedback.
-
If you can make a codesandbox repro etc I am happy to help debug the issue. |
Beta Was this translation helpful? Give feedback.
-
Here's a sandbox showing the issue at hand. I have another one (which I'll setup) where I was able to fix the issue by adding in that useEffect hook. https://codesandbox.io/s/determined-germain-rlvut?file=/src/App.tsx |
Beta Was this translation helpful? Give feedback.
-
Thanks for the example. I can see a few issues in the code:
I think the cause of the issue is that you were trying to use An |
Beta Was this translation helpful? Give feedback.
-
I wrote this custom hook that uses the
useObervableSuspense
to retrieve anObservable<T>
value from a custom AnyRepository class (implementation not shown) based on an id string.The value of the ID is gotten from the
react-router
(v6)useParams()
hook like so:and is passed to the custom
useFindSuspense
hook.Currently, when the route is changed, the
useObservableSuspense
hook returns the same value.This is despite the underlying
Observable<T>
andfind$
changing and also theid
/deckId
input.I've tried to the following:
Note: Adding this line of code:
prints the Changed to the console as expected (on route change) but the value returned from the hook and the
useObservableSuspense
hook is unchanged.useEffect
to manually update the resourceBoth of which did not do anything, even when the ObservableResource itself changed and it's inputs have changed.
So I assumed that this was because there's no way to specify custom dependencies for the
useObservableSuspense
hook, which could be "re-calculated" if those dependencies changed.I will go and try patch the hook to get a working solution, but I think that is what might be nescessary.
Beta Was this translation helpful? Give feedback.
All reactions