import React from 'react'; import { Button, Form, Input } from 'antd'; import type { FormItemProps } from 'antd'; const MyFormItemContext = React.createContext<(string | number)[]>([]); interface MyFormItemGroupProps { prefix: string | number | (string | number)[]; } function toArr(str: string | number | (string | number)[]): (string | number)[] { return Array.isArray(str) ? str : [str]; } const MyFormItemGroup: React.FC> = ({ prefix, children, }) => { const prefixPath = React.useContext(MyFormItemContext); const concatPath = React.useMemo(() => [...prefixPath, ...toArr(prefix)], [prefixPath, prefix]); return {children}; }; const MyFormItem = ({ name, ...props }: FormItemProps) => { const prefixPath = React.useContext(MyFormItemContext); const concatName = name !== undefined ? [...prefixPath, ...toArr(name)] : undefined; return ; }; const App: React.FC = () => { const onFinish = (value: object) => { console.log(value); }; return (
); }; export default App;