-
Notifications
You must be signed in to change notification settings - Fork 9
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
hooks useMutation and useQuery #642
Conversation
replace noun participle better name it affirmative:
|
const requestRef = useRef(request) | ||
const onSuccessRef = useRef(onSuccess) | ||
const onErrorRef = useRef(onError) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need to set these props into a ref?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, I guess is to avoid the dependency in the useCallback
for the fetch
function so it does not get recomputed if the callbacks reference change. But what happens with this internal onSuccessRef if the onSuccess reference changes? Imagine a case where you need to recreate a new onSuccess callback when, for example, the id
parameter changes so your callback looks like this: () => console.log(id)
and the id
comes from the outer scope. Does the onSuccessRef get updated with the new value?
closing this PR, a wider agreement is required before we come to materialise this |
} | ||
}, []) | ||
|
||
const refresh = useCallback( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If fetch
is already memorized, the use of useCallback
here might be a downgrade instead of an upgrade in performance. The same for the other functions that only depend on the fetch
These hooks are useful for better state management of data fetching / mutation.
useMutation
Useful when creating, updating or removing data from a source.
Perform a given mutation and update the status of it.
useQuery
Hook to fetch data from a source and receive a status update.
Basic usage
Perform a given query and update the status of it
Initial state
Use
initialData
prop to avoid executing the query when the component is mounted. Useful when using Server-Side rendering.Interval
Execute the query every
refetchInterval
millisecondsDisabled mount execution
Disable mount fetch assigning
isExecuteOnMountDisabled
prop totrue