如何解决使用 Hooks 将数据从子组件传递到父组件
我想从 Child 组件传递 myVarible 并在 App(父)组件中检索它,然后将它放在 initialLang 属性上。
家长:
imports ...
// Here there is not "class App extends React.Component {" !!!
const App = () => (
<Provider store={store}>
<I18n translations={translations} initialLang="en" fallbackLang="en"></I18n>
</Provider>
);
export default App;
孩子:
imports ...
// Here there is not "class Child extends React.Component {" !!!
const ChildInner = ({context}) => (
{
<View style={{flexDirection: "row"}}>
<Picker
onValueChange={(itemValue,itemIndex) => {
if ( itemIndex == 0 ) {
myVariable = 'en';
} else if ( itemIndex == 1 ) {
myVariable = 'fr';
}
}}
>
<Picker.Item label="English" value="en" />
<Picker.Item label="french" value="fr" />
</Picker>
</View>
}
);
const Child = (context) => (
...
);
Child.propTypes = {
....
};
Child.contextTypes = {
t: PropTypes.func.isRequired,};
export default Child;
我不知道在使用钩子时如何使用道具或状态来做到这一点。感谢您的帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。