Skip to content

Commit

Permalink
fix: review
Browse files Browse the repository at this point in the history
  • Loading branch information
elevensky committed Apr 19, 2023
1 parent c89c7d2 commit d1d5e2f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
15 changes: 10 additions & 5 deletions src/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -627,17 +627,14 @@ class Field extends React.Component<InternalFieldProps, FieldState> implements F
function WrapperField<Values = any>({ name, ...restProps }: FieldProps<Values>) {
const fieldContext = React.useContext(FieldContext);
const listContext = React.useContext(ListContext);
const mergedIsListField = restProps.isListField || (!restProps.isList && !!listContext);
const namePath = name !== undefined ? getNamePath(name) : undefined;

let key: string = 'keep';
if (!restProps.isListField) {
key = `_${(namePath || []).join('_')}`;
}

if (restProps.isListField === undefined && !restProps.isList && listContext) {
restProps.isListField = listContext.inList;
}

// Warning if it's a directly list field.
// We can still support multiple level field preserve.
if (
Expand All @@ -649,7 +646,15 @@ function WrapperField<Values = any>({ name, ...restProps }: FieldProps<Values>)
warning(false, '`preserve` should not apply on Form.List fields.');
}

return <Field key={key} name={namePath} {...restProps} fieldContext={fieldContext} />;
return (
<Field
key={key}
name={namePath}
isListField={mergedIsListField}
{...restProps}
fieldContext={fieldContext}
/>
);
}

export default WrapperField;
1 change: 0 additions & 1 deletion src/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ const List: React.FunctionComponent<ListProps> = ({
const pathName = namePath[len];
return [keyManager.keys[pathName], namePath.slice(len + 1)];
},
inList: true,
}),
[prefixName],
);
Expand Down
1 change: 0 additions & 1 deletion src/ListContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { InternalNamePath } from './interface';

export interface ListContextProps {
getKey: (namePath: InternalNamePath) => [React.Key, InternalNamePath];
inList: boolean;
}

const ListContext = React.createContext<ListContextProps | null>(null);
Expand Down

0 comments on commit d1d5e2f

Please sign in to comment.