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