DouyinFE / semi-design

🚀A modern, comprehensive, flexible design system and React UI library. 🎨 Provide more than 3000+ Design Tokens, easy to build your design system. Make Semi Design to Any Design. 🧑🏻‍💻 Design to Code in one click
https://semi.design
Other
8.49k stars 717 forks source link

[Form] formApi.setValues update ArrayField not work when executing at Parent component didMount #1409

Open pointhalo opened 1 year ago

pointhalo commented 1 year ago

Is there an existing issue for this?

Which Component

Form

Semi Version

v2.28.0

Current Behavior

Expected Behavior

Steps To Reproduce

No response

ReproducibleCode

class ArrayFieldSetValues extends React.Component {
    constructor() {
        super();
        this.state = {
            data: {
            },
        };
        this.getFormApi = this.getFormApi.bind(this);
    }

    componentDidMount() {
        this.formApi.setValues({
            effects: [
                { name: "脸部贴纸", type: "2D" },
                { name: "前景贴纸", type: "3D" },
            ],
            test: 'fff'
        })
    }

    getFormApi(formApi) {
        this.formApi = formApi;
    }

    render() {
        return (
            <Form
                // onChange={(...v) => console.log(v)}
                onValueChange={(...v) => console.log(v)}
                getFormApi={this.getFormApi}>
                <Row>
                    <Col span={12}>
                        <ArrayField field="effects">
                            {({ add, arrayFields }) => (
                                <React.Fragment>
                                    <Button onClick={add} type="primary">Add</Button>
                                    {
                                        arrayFields.map(({ field, key, remove }, i) => (
                                            <div key={key}>
                                                <Input
                                                    field={`${field}[name]`}
                                                    label={`${field}.name`}
                                                    // initValue='test'
                                                />
                                                <Input
                                                    field={`${field}[time]`}
                                                    label={`${field}.time`}
                                                />
                                                <Button type="danger" onClick={remove}>remove</Button>
                                            </div>
                                        ))
                                    }
                                </React.Fragment>
                            )}
                        </ArrayField>
                        <Form.Input field="test" label="Test" />
                        <Space>
                            <Button htmlType='reset'>Reset</Button>
                        </Space>
                    </Col>
                    <Col span={12}>
                        <ComponentUsingFormState />
                    </Col>
                </Row>
            </Form>
        );
    }
}

Environment

- OS:
- browser:

Anything else?

No response

rojer95 commented 1 year ago

这个bug有能先workaround的方法吗?