Skip to content

Commit

Permalink
fix: reset导致visbleFieldKey清空,错误信息无法展示
Browse files Browse the repository at this point in the history
  • Loading branch information
mengshang918 committed Jan 14, 2022
1 parent 2e252aa commit c4d839c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions packages/drip-form/src/DripForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: jiangxiaowei
* @Date: 2020-05-14 16:54:32
* @Last Modified by: jiangxiaowei
* @Last Modified time: 2022-01-13 16:21:24
* @Last Modified time: 2022-01-14 19:22:57
*/
import React, {
forwardRef,
Expand Down Expand Up @@ -159,6 +159,14 @@ const DripForm = forwardRef<DripFormRefType, DripFormRenderProps>(
customProps,
]
)

// visibleFieldKey为组件初次加载设置,reload不会触发组件卸载操作,只是重置数据
const resetArgs = useMemo(() => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { visibleFieldKey, ...resetArgs } = initArgs
return resetArgs
}, [initArgs])

const [data, dispatch] = useImmerReducer<State, Action>(
formDataReducer,
initArgs
Expand All @@ -175,7 +183,7 @@ const DripForm = forwardRef<DripFormRefType, DripFormRenderProps>(
) {
dispatch({
type: 'reload',
...initArgs,
...resetArgs,
})
}
}, [
Expand All @@ -190,6 +198,7 @@ const DripForm = forwardRef<DripFormRefType, DripFormRenderProps>(
prevUnitedSchema,
unitedSchema,
reload,
resetArgs,
])

const {
Expand Down Expand Up @@ -246,9 +255,9 @@ const DripForm = forwardRef<DripFormRefType, DripFormRenderProps>(
const reset = useCallback(() => {
dispatch({
type: 'reload',
...initArgs,
...resetArgs,
})
}, [dispatch, initArgs])
}, [dispatch, resetArgs])

// 向外抛出表单数据
useImperativeHandle<DripFormRefType, DripFormRefType>(
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export type State = {

type ReloadAction = {
type: 'reload'
} & State
} & Omit<State, 'visibleFieldKey'>

type SetDataSchemaAction = {
type: 'setDataSchema'
Expand Down

0 comments on commit c4d839c

Please sign in to comment.