【发布时间】:2019-05-29 10:12:25
【问题描述】:
我在 react native 中创建了一个样板。当我有父母并且必须有孩子的组件并且我想将状态从孩子 1 传递到孩子 2 时
我尝试发送给父母然后是孩子2,但没有工作
这是我的代码 家长
class WashingPackageMotor extends Component {
render() {
return (
<View style={styles.containerMain}>
<Grid scrollable>
<Section>
<Block size="100%">
<ComponentWashingPackage />
</Block>
</Section>
<Section>
<Block size="100%">
<ComponentList />
</Block>
</Section>
</Grid>
<Grid>
<Section>
<Block size="100%">
<ComponentBottom />
</Block>
</Section>
</Grid>
</View>
}
);
}
}
孩子 1(兄弟姐妹)
export default class ComponentList extends Component {
constructor(props) {
super(props)
this.state = {
value: 0,
amount: 0,
v0: 0,
v1: 0,
collapsed: false
// v5: 0,
// v6: 0
}
this.amount = 0
}
..........
..........
}
孩子 2(兄弟姐妹两个)
class ComponentBottom extends Component {
render() {
return (
<Grid>
<View style={styles.bottomView}>
<View style={{ borderBottomColor: '#EEEEEE', borderBottomWidth:0.5}}/>
<Section>
<Block size="60%">
<Text style={styles.textHarga}>Total Harga</Text>
<Text style={styles.textPrice}>Rp 180.000</Text>
</Block>
<Block size="40%">
<ButtonProcessDisabled onPress={() => this.props.navigation.navigate('OrderConfirmation')}/>
</Block>
</Section>
</View>
</Grid>
)
}
}
以及如何将状态从子 1(兄弟 1)发送到子 2(兄弟 2)
【问题讨论】:
标签: javascript reactjs react-native state react-props