react父组件传入子组件的props不更新问题


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 思否


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM