import './demo12.css'; import Button from '../../button'; import Field from '..'; import React from 'react'; import ReactDOM from 'react-dom'; interface PageStates { value: any; } interface PageProps { value?: any; onChange: (value: any) => void; } class Custom extends React.Component { onAdd: () => void; constructor(props) { super(props); this.onAdd = () => { const value = this.state.value.concat([]); value.push('new'); this.setState({ value, }); this.props.onChange(value); }; this.state = { value: typeof props.value === 'undefined' ? [] : props.value, }; } // update value componentWillReceiveProps(nextProps) { if ('value' in nextProps) { this.setState({ value: typeof nextProps.value === 'undefined' ? [] : nextProps.value, }); } } render() { return (
{this.state.value.map((v, i) => { return ; })}
); } } /* eslint-disable react/no-multi-comp */ class App extends React.Component { field: Field; constructor(props) { super(props); this.field = new Field(this, { // @ts-ignore deepReset: true, }); } onGetValue() { console.log(this.field.getValue('custom')); } render() { const { init, setValue, reset } = this.field; return (


); } } ReactDOM.render(, document.getElementById('field-demo-12'));