- Notifications
You must be signed in to change notification settings - Fork 24
[v3] eliminates deps array and relies on argument ref equality #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| Published https://www.npmjs.com/package/react-hooks-async/v/3.0.0-alpha.1 @ed-sparkes @digitaltopo |
| Hmm sorry took me a while to get to this. Its not behaving the same, i removed the dependencies but now only one of my request gets called I have my data retrieval tasks dependent on my get access token task as such and an example of one of the tasks ... Each of the subsequent tasks are axios requests to get data but none are now being fired with alpha-1 |
| Oh no. I’d like to dig into it. Is it easy for you to build reproduction? |
| hmm ill try and put a codesandbox together looks like i need to add an additional useMemo otherwise i get infinite calls to my getProjectsTask so i have updated to the below but with the condition |
| Here is our previous code sandbox updated to use the latest version https://codesandbox.io/s/inspiring-architecture-4gfwy as you can see previously when the count was defined the second task ran, now it does not |
| i didnt really understand the motivation for the change as it seems there is more complexity for the consumer in having to create a separate useMemo with the dependencies rather than just pass the dependencies to your hook? Not saying it is wrong, but keen to understand the motivation for the move to ref equality over dependencies |
| In the meantime is there anyway of going back to previous alpha i tried updating package json but its still go the latest version without deps |
https://www.npmjs.com/package/react-hooks-async/v/3.0.0-alpha.0 You want to use the exact version. |
v2 APIs were not consistent, some of them require There was a reason why I added Meanwhile, React community tends to take "memoization at consumer end" more idiomatic. (No official source, but tweets, issues, and so on.) |
Thanks for the updated version. I updated your example. https://codesandbox.io/s/frosty-feistel-1648t |
| Hmm ok my real example is a little different as I am using useAsyncTask rather than the axios equiv for getting the token ... the geTokenSilently function returns a string i have tried to simulate this with a setTimeout and updated the code sandbox |
| https://codesandbox.io/s/great-browser-zhgh5 Here you go. Instead of If you want to |
| ah yes, that should have been obvious, i did it for the axios tasks using useMemo but nor for the other async task doh thank you for your patience |
| Unless there are any other concerns, I will publish v3.0.0 later. |
It seems like the idiomatic React prefers ensuring argument referential equality on the caller end, to accepting
depsin hooks.This is going to be a big breaking change. (Actually, it's been changing back and forth.)
I made a choice to depend on use-memo-one by @alexreardon .
Feedback welcomed.