采纳答案成功!
向帮助你的同学说点啥吧!感谢那些助人为乐的人
老师代码中 有的继承 Component 有的继承Component 他们两个有什么区别么?什么情况下继承Component ,什么情况下继承Component?
从RN0.53.0开始React.Component支持携带两个类型的参数Props 与 State ,通过Component<Props>我们可以约束Props中属性的类型:
type Props = {
foo: number,
};
type State = {
bar: number,
class MyComponent extends React.Component<Props, State> {
state = {
bar: 42,
render() {
return
this
.props.foo +
.state.bar;
}
这是一个新特性哈,可以使用也可以不使用,stackoverflow上有个关于它的不错的讨论也可以参考下:
https://stackoverflow.com/questions/51338438/react-native-what-is-type-props
非常感谢!
那这个与props-type的区别是?
从对props的约束检查上两者效果是一样的
登录后可查看更多问答,登录/注册
解锁React Native开发应用新姿势,React Native新版本热门技术
1.8k 2
1.5k 3
2.1k 4
2.1k 2
1.4k 1
购课补贴联系客服咨询优惠详情
慕课网APP您的移动学习伙伴
扫描二维码关注慕课网微信公众号