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 got into a bit of a pickle with transform() function from form helper. I needed to set one of the fields to a value passed to submit function, but after calling transform, it sets the values correctly the first time, but after for example I get validation errors and then submit it again with different value passed to the submit function, transform function is stale and has the first value only.
For example:
I had two buttons to submit the form and needed each one to set status to different value
function submit(e, _status = false) {
e.preventDefault();
transform((d) => {
//_status here is stale after first submit
return {
...d,
status: _status,
SOME_OTHER_TRANSFORMS
}
})
post('SOME_ROUTE', {
preserveState: true
})
}
I managed to find, that transform is being reassigned to the passed callback and that seemed to be the reason of getting stale values. I was able to customize the hook by keeping transform function as just assignment one and making new variable that holds the callback, which is the used to transform the data.
I'm not completly sure if what I'm doing here is completly fine or if it could mess with some other things in the hook. Also I could have just used normal Inertia.post() and transformed data before that, but that just didn't feel right to me after using the helper.
Do you guys have any ideas if I might be using the transform wrong or maybe do you think this could be considered bug?
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 got into a bit of a pickle with transform() function from form helper. I needed to set one of the fields to a value passed to submit function, but after calling transform, it sets the values correctly the first time, but after for example I get validation errors and then submit it again with different value passed to the submit function, transform function is stale and has the first value only.
For example:
I had two buttons to submit the form and needed each one to set status to different value
I managed to find, that transform is being reassigned to the passed callback and that seemed to be the reason of getting stale values. I was able to customize the hook by keeping transform function as just assignment one and making new variable that holds the callback, which is the used to transform the data.
Changed it from:
To:
I'm not completly sure if what I'm doing here is completly fine or if it could mess with some other things in the hook. Also I could have just used normal Inertia.post() and transformed data before that, but that just didn't feel right to me after using the helper.
Do you guys have any ideas if I might be using the transform wrong or maybe do you think this could be considered bug?
Beta Was this translation helpful? Give feedback.
All reactions