Skip to content

Commit

Permalink
use ref for storing the transform callback
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmonat authored May 5, 2022
1 parent 85b5694 commit 53b40db
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/inertia-react/src/useForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function useForm(...args) {
const [progress, setProgress] = useState(null)
const [wasSuccessful, setWasSuccessful] = useState(false)
const [recentlySuccessful, setRecentlySuccessful] = useState(false)
let transform = (data) => data
const transform = useRef((data) => data)

useEffect(() => {
isMounted.current = true
Expand Down Expand Up @@ -115,9 +115,9 @@ export default function useForm(...args) {
}

if (method === 'delete') {
Inertia.delete(url, { ..._options, data: transform(data) })
Inertia.delete(url, { ..._options, data: transform.current(data) })
} else {
Inertia[method](url, transform(data), _options)
Inertia[method](url, transform.current(data), _options)
}
},
[data, setErrors],
Expand All @@ -142,7 +142,7 @@ export default function useForm(...args) {
wasSuccessful,
recentlySuccessful,
transform(callback) {
transform = callback
transform.current = callback
},
setDefaults(key, value) {
if (typeof key === 'undefined') {
Expand Down

0 comments on commit 53b40db

Please sign in to comment.