Both the react- master component and the parent component should control the explicit and recessive of the grandson component.

for example, both the master component and the parent component have to control the explicit and recessive of the grandson component, how to control it?

Oct.25,2021

it is recommended to write as a level component, so that only one prop, is easier to control.
if you have to write this,
1, define the prop of the grandchild component in the outermost layer (master component) (the default false), is passed to the parent component, determine whether the prop has changed in the componentWillReceiveProps hook of the parent component, and modify the state, of the parent component to pass to the grandchild component according to this change.
2. The control of the parent component has nothing to do with the outermost component, just modify the state directly.

A better way is to control a prop, with redux or mobx,.


go straight to the code:

class GF {
    state = {visibel: false}
    render() {
        return (
        <>
            <Parent visible={this.state.visible}/>
            <Child visible={this.state.visible}/>
        </>
       );
    }
}

class Parent {
    render() {
        return <Child visible={this.props.visible}/>
    }
}

class Child {
    render() {
        return <div visible={this.props.visible}></div>
    }
}

make up the rest by yourself.

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