inertia
inertia copied to clipboard
Memoize `transform` to fix long standing `useForm` bug
I'm opening another PR to fix this bug (#1171, #1131, #1491, #1631)
In the React useForm
package, the transform
function is set as a local variable in the component. This means that if the page triggers any re-render, the transform
variable is re-initialized to the placeholder function ((data) => data
). For this reason, it's more likely than not that the transform method does nothing, rendering the docs inaccurate.
The previous PRs were closed without being read. I think the whole React community here would really appreciate this bug finally being fixed.
@reinink Any idea when this might be merged? 🙏
I need this fix as well! The transform
callback is being overridden by the default (data) => data
after doing something basic like form.setData
.
Repro steps:
const myCallback = (data) => {
console.log("myCallback")
return data
}
form.transform(myCallback)
form.post('some/url', { onSuccess: ({ props }) => {
form.setData(props.formData)
form.post('some/url') // "myCallback" is not printed out
})
I added a package containing this fix in the npm registry if anyone is interested: https://www.npmjs.com/package/@moraki/inertia-react
Yay, thanks! Now what?
Please forgive me for tagging... @claudiodekker @jessarcher @thecrypticace Can this PR get some feedback? Thanks for your time and hard work.
It would sure be great to get this long standing bug fixed. Hoping this is the bump that gets attention. @reinink