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 思否
原文:https://www.cnblogs.com/xiaqiuchu/p/14720012.html