The method of calling child components by react parent component

I want to call the method of the subcomponent, but I can"t find the method of the subcomponent when printing.

Mar.11,2021

you use shouldhide on state to show different parts.

when shouldhide is true , the second half is not displayed. So you can't get this.refs.test .

also, if you want to do something related to state after calling setState , you should wait until setState is finished.

because setState is an asynchronous operation, you cannot follow the Synchronize operation on the figure. It should look like this:

this.setState({
  shouldhide: true
}, () => {
  console.log(this.refs.test)
})

but in fact, you can get this.refs.test only if shouldhide is false .

modify BasicEdit to the following:

BasicEdit = () => {
    this.setState({
        shouldhide: true
    }, () => {
        setTimeout(() => {
            console.log(this.refs.test)
        }, 500)
    })
}

shouldhide when you set it to false, you render the data in if, but there is no ref in if

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-1e488c7-4444d.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-1e488c7-4444d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?