You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I'm trying to make a simple reusable modal that calls a mutation and tracks the status of the mutation call.
I want the component to support various mutations so my first thought was to pass mutate function and status as props to the child component (the reusable modal).
constParent=()=>{const{ mutate, status }=useMutation({mutationFn: ()=>newPromise((resolve)=>setTimeout(()=>resolve("test"),3000)),});return<ChildonMutate={mutate}status={status}/>;};
constChild=({ onMutate, status }: Props)=>{return(<div><buttononClick={onMutate}>Mutate</button><div>{status}</div></div>);};
the mutate function works fine but status state is not being updated inside the child component. Can anyone give me feedback on this particular situation?
I was able to work around the problem using useMutationStatus but I am still very curious to why the approach above doesn't work as expected. I am new to the tanstack world, so I might be missing something... I'd be grateful for some advice.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi, I'm trying to make a simple reusable modal that calls a mutation and tracks the status of the mutation call.
I want the component to support various mutations so my first thought was to pass
mutate
function andstatus
as props to the child component (the reusable modal).the
mutate
function works fine butstatus
state is not being updated inside the child component. Can anyone give me feedback on this particular situation?I was able to work around the problem using
useMutationStatus
but I am still very curious to why the approach above doesn't work as expected. I am new to the tanstack world, so I might be missing something... I'd be grateful for some advice.(Something like this)
Beta Was this translation helpful? Give feedback.
All reactions