我从.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/