之间的区别是什么高阶组件(HOC)和继承反应本地组件

我从.net背景,反应新本地

这里的问题是如何的不同于继承与基地哦概念通过父类属性和儿童扩展基础和使用状态,从基类属性和基本方法。

这是最好的方法来实现 父- >子- >孙子 在反应组件。层次关系吗?

例如:

Parent.js 看起来像


class Parent extends Component {     constructor(props)     {         super(props);         this.state = {             value: "Parent",             BaseText: "Inheritance Example"         }     }     onUpdate = () => {         console.log("Update called at Parent")     } }


Child.js 延伸Parent.js


class Child extends Parent {     constructor(props)     {         super(props);        //this state should inherit the properties of Parent and override only the value property         this.state = {             value: "Child",         }     }     onUpdate = () => {         super.onUpdate();         console.log("Update called at Child view")     }     render()     {         return(             <View>                 <Text> Child View</Text>             </View>         )     } }


GrandChild.js 从Child.js延伸


class GrandChild extends Child     {         constructor(props)         {             super(props);            //this state should inherit the properties of Child, Parent and properties specific to this             this.state = {                 value: "GrandChild",                 Name: "Test Grand Child"             }         }         onUpdate = () => {             super.onUpdate();             console.log("Update called at Grand Child view")         }         render()         {             return(                 <View>                     <Text> Grand Child View</Text>                 </View>             )         }     }


这是正确的方式实现 抽象 在反应的家乡 说,父类有共同状态属性和子继承了父状态和有自己的属性。

如何继承状态以及如何更新值状态,在这种情况下。


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31559515/viewspace-2219457/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/31559515/viewspace-2219457/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值