mirror of
https://github.com/Myzel394/kleckrelay-website.git
synced 2025-06-18 23:45:26 +02:00
fixed FormikAutoLockNavigation.tsx
This commit is contained in:
parent
2cb17e5550
commit
fd27a8ca74
@ -1,27 +1,29 @@
|
||||
import {FormikContextType} from "formik"
|
||||
import {useContext} from "react"
|
||||
import {useDeepCompareEffect} from "react-use"
|
||||
import {useShallowCompareEffect} from "react-use"
|
||||
import deepEqual from "deep-equal"
|
||||
|
||||
import LockNavigationContext from "./LockNavigationContext"
|
||||
|
||||
export interface LockNavigationContextProviderProps {
|
||||
formik: FormikContextType<any>
|
||||
|
||||
active?: boolean
|
||||
}
|
||||
|
||||
export default function FormikAutoLockNavigation({
|
||||
formik,
|
||||
active = true,
|
||||
}: LockNavigationContextProviderProps): null {
|
||||
const {lock, release} = useContext(LockNavigationContext)
|
||||
|
||||
// TODO: Not working yet
|
||||
useDeepCompareEffect(() => {
|
||||
if (!deepEqual(formik.values, formik.initialValues)) {
|
||||
useShallowCompareEffect(() => {
|
||||
if (!deepEqual(formik.values, formik.initialValues) && active) {
|
||||
lock()
|
||||
} else {
|
||||
release()
|
||||
}
|
||||
}, [lock, release, formik.values, formik.initialValues])
|
||||
}, [lock, release, formik.values, formik.initialValues, formik.isSubmitting, active])
|
||||
|
||||
return null
|
||||
}
|
||||
|
@ -293,7 +293,7 @@ export default function AliasNotesForm({id, notes, onChanged}: AliasNotesFormPro
|
||||
</Grid>
|
||||
</Grid>
|
||||
</form>
|
||||
<FormikAutoLockNavigation formik={formik} />
|
||||
<FormikAutoLockNavigation active={isInEditMode} formik={formik} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user