The instance method of a sub-component wrapped by Form in antdesign cannot be called after it is obtained through refs.

react beginners, there is a question that is not clear:
Click the button to execute this.calcAccount ();

1. Why is it undefined when you get the child component through refs and call its instance method test (),?
Note: this subcomponent is wrapped by Form.create () (ElectricityTemp), which is the method provided by the From component in antdesign.
the following two components remove unnecessary code.

parent component: ElectricityFees.tsx

class ElectricityFees extends React.Component<Iprops, Istate> {

    constructor(props: any) {
        super(props);
        this.calcAccount = this.calcAccount.bind(this);
    }

    public calcAccount: (e: any) => void = (e: any) => {
        const self = this;
        this.props.rooms.forEach((_:object, i:number) => {
            const a = self[`refs${i}`].current; **// atest?**
            a.test();
        });
    };


    public render() {
        const key: string = "name";
        this.props.rooms.forEach((_:object, i:number) => {
            this[`refs${i}`] = React.createRef();
        });

        return (

            <React.Fragment>
                <Row gutter={24}>
                    {
                        this.props.rooms.map((_: object, i: number) => {
                            return (
                                <Col className="gutter-row" span={6} key={i}>
                                    <WrappedTimeRelatedForm name={_[key]} ref={this[`refs${i}`]}/>
                                </Col>
                            )
                        })
                    }
                </Row>
                <Button onClick={this.calcAccount}></Button>
            </React.Fragment>
        )
    }
}

export default ElectricityFees;

subcomponent: WrappedTimeRelatedForm.tsx

class ElectricityTemp extends React.Component<Iprops, any> {

     public test(){
            console.log(this.props.name);
     }
    public render() {
        return (
            <Form>
                ...
            </Form>
        );
    }
}


const WrappedTimeRelatedForm = Form.create()(ElectricityTemp);

export default WrappedTimeRelatedForm;
Apr.22,2021

name={`${_}${key}`}

have you solved it? I also encountered the same problem that the parent component cannot call the method of the child component form


for the code you give:
do not define this as something else, it is not necessary. The set of jQuery needs to be discarded.
this [`refs$ {I} `] .test ()
is fine.
for refs I want to write more:
first of all: refs cannot be used in stateless components.
in fact, try not to use refs in the worst case.
what is the way the parent component invokes the child component to get the child component?
if it is data, then the parent component can give a callback to the child component.
if you want to execute the methods of a child component, you can wrap the child component in the parent component, which can be implemented through a higher-level component, for example:

<Children>
    <Parent />
</Children>
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eb441d-48293.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eb441d-48293.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?