export default class Index extends Component {
    // 接受新props更新,注意设置的参数是nextProps
    componentWillReceiveProps(nextProps) {
        this.setState({
            isShow: nextProps.isShow
        });
    }
    constructor() {
        super(...arguments)
        this.state = {
            isShow: false,
        }
    }
    render() {
        const { isShow } = this.state;
        return (
            <View className={isShow ? "show" : "hide"}>
             
            </View>
        )
    }
}

参考:React中传入组件的props改变时更新组件的几种实现方法 - SegmentFault 思否

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-25
  • 2021-10-02
  • 2021-10-23
  • 2022-03-09
  • 2022-12-23
猜你喜欢
  • 2021-10-02
  • 2021-11-12
  • 2021-06-11
  • 2022-02-02
  • 2022-12-23
  • 2022-12-23
  • 2021-08-13
相关资源
相似解决方案