chore: prevent leave without saving from appearing when not needed (#8200)

This commit is contained in:
Jarrod Flesch
2024-09-13 10:48:47 -04:00
committed by GitHub
parent 9548961ec9
commit dd5a9acb60

View File

@@ -8,15 +8,15 @@ type Props = {
readOnly: boolean readOnly: boolean
} }
export function TenantFieldComponentClient({ initialValue, path, readOnly }: Props) { export function TenantFieldComponentClient({ initialValue, path, readOnly }: Props) {
const { formInitializing, setValue } = useField({ path }) const { formInitializing, setValue, value } = useField({ path })
const hasSetInitialValue = React.useRef(false) const hasSetInitialValue = React.useRef(false)
React.useEffect(() => { React.useEffect(() => {
if (!hasSetInitialValue.current && !formInitializing && initialValue) { if (!hasSetInitialValue.current && !formInitializing && initialValue && !value) {
setValue(initialValue) setValue(initialValue)
hasSetInitialValue.current = true hasSetInitialValue.current = true
} }
}, [initialValue, setValue, formInitializing]) }, [initialValue, setValue, formInitializing, value])
return ( return (
<RelationshipField <RelationshipField