Skip to content

Commit

Permalink
fix(react): fix field unmounted but can not update right model
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang committed Oct 17, 2023
1 parent 421073e commit 7760435
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/react/src/components/Field.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react'
import React, { useEffect } from 'react'
import { useField, useForm } from '../hooks'
import { useAttach } from '../hooks/useAttach'
import { ReactiveField } from './ReactiveField'
import { FieldContext } from '../shared'
import { JSXComponent, IFieldProps } from '../types'
Expand All @@ -10,9 +9,13 @@ export const Field = <D extends JSXComponent, C extends JSXComponent>(
) => {
const form = useForm()
const parent = useField()
const field = useAttach(
form.createField({ basePath: parent?.address, ...props })
)
const field = form.createField({ basePath: parent?.address, ...props })
useEffect(() => {
field?.onMount()
return () => {
field?.onUnmount()
}
}, [field])
return (
<FieldContext.Provider value={field}>
<ReactiveField field={field}>{props.children}</ReactiveField>
Expand Down

0 comments on commit 7760435

Please sign in to comment.