import React, { useState, useRef } from 'react'; import { Form, Col, Row, Button, ArrayField, Space, useFormState } from '@douyinfe/semi-ui'; import { IconMinusCircle, IconPlusCircle, IconRefresh } from '@douyinfe/semi-icons'; import { JSONTree } from 'react-json-tree'; const FormStateTree = () => { const formState = useFormState(); return ( true} hideRoot data={formState} /> ); }; const NestDemo = () => { const formRef = useRef(); const getFormApi = () => { const formApi = formRef.current.formApi; return formApi; }; const formInitValues = { data: [ { name: '0', rules: [ { desc: '0-0-desc', type: '0-0-type' }, { desc: '0-1-desc', type: '0-1-type' }, ], }, { name: '1', rules: [ { desc: '1-0-desc', type: '1-0-type' } ], } ] }; // const setValueChangeOutSide = () => { // const formApi = getFormApi(); // formApi.setValue('data', [ // { // name: 'new-0', // rules: [ // { desc: 'new-0-0-desc', type: 'new-0-0-type' }, // { desc: 'new-0-1-desc', type: 'new-0-1-type' }, // ], // }, // { // name: 'new-1', // rules: [ // { desc: 'new-1-0-desc', type: 'new-1-0-type' }, // ], // }, // { // name: 'new-2', // rules: [ // { desc: 'new-2-0-desc', type: 'new-2-0-type' }, // { desc: 'new-2-1-desc', type: 'new-2-1-type' }, // { desc: 'new-2-2-desc', type: 'new-2-2-type' }, // ], // } // ]); // }; // const setValueChangeInside = () => { // const formApi = getFormApi(); // formApi.setValue('data[0].rules', [{ desc: 'new-0-0-desc-in', type: 'new-0-0-type-in' }]); // }; // const setValueChangeRow = () => { // const formApi = getFormApi(); // formApi.setValue('data[0].rules[0]', { type: 'special-row-type', desc: 'special-row-desc' }); // }; return (
{({ add, arrayFields, addWithInitValue }) => ( {/* */} { arrayFields.map(({ field, key, remove }, i) => (
{key.slice(0, 10)}
)) }
)}
); }; NestDemo.storyName = 'ArrayField-Nested init value'; export default NestDemo;