美文网首页
react-native 学习组件封装

react-native 学习组件封装

作者: 小酷酷非常酷 | 来源:发表于2020-06-16 15:30 被阅读0次

1.static proTypes 类似于iOS 的Block 需要声明,向外传递,和定义你这个方法的属性(事件,参数,或者等等)
比如:static propTypes = {
A:PropTypes.func,
B:ProTypes.number
C:ProTypes.array
}
2.参数传递(这个和iOS 有点不一样,iOS 需要子类定义这个字段,调用者才可以传递,但是react-native 不需要, 调用者可以直接定义参数,至于用不用就是你组件的事情,与我无关)
3.调用者传进来的参数,可以通过props 拿到, 需要声明 const {} = this.props, 或者 this.props. 拿到
4.调用者改变某一个值,需要改变组件的状态需要在componentWillReceiveProps 接收到这个props 然后作出相应的改变,例如:this.setState方法,或者调用相应的方法
比如:componentWillReceiveProps(nextProps){
this.convertPropsToStates(nextProps);
}
convertPropsToStates(props){
}

相关文章

网友评论

      本文标题:react-native 学习组件封装

      本文链接:https://www.haomeiwen.com/subject/ordgtktx.html