Javascript 反应/重复通过状态更改<;选择器>;

Javascript 反应/重复通过状态更改<;选择器>;,javascript,reactjs,react-native,redux,react-redux,Javascript,Reactjs,React Native,Redux,React Redux,我正在使用react native Picker组件,在值更改时更新全局状态时遇到问题 我以前没有使用过Redux,读到它是将状态传递给另一个非父/子组件的唯一解决方案之一。我有一个Network.js文件,它处理一个API。我想在用户选择值并更新状态时,将状态传递给Network.js 这是我的应用程序组件和PageOne组件的代码 App.js。非常感谢 const initialState={ 计数:0 }; const reducer=(state=initialState,action

我正在使用react native Picker组件,在值更改时更新全局状态时遇到问题

我以前没有使用过Redux,读到它是将状态传递给另一个非父/子组件的唯一解决方案之一。我有一个Network.js文件,它处理一个API。我想在用户选择值并更新状态时,将状态传递给Network.js

这是我的应用程序组件和PageOne组件的代码 App.js。非常感谢
const initialState={
计数:0
};
const reducer=(state=initialState,action)=>{
如果(action.type==“REGIONAL_ID”){
返回{
regionId:state.regionId
};
}
返回状态;
}
const store=createStore(reducer);
导出默认类App扩展React.Component{
render(){
返回(
)
}  

}
在App.js中,您应该返回一个新状态:

在PageOne.js中,只需执行以下操作:

changeRegion = (regId) => {
  // How to add/dispatch the regId to the prop 
  this.props.dispatch({ type: 'REGIONAL_ID', regionId: regId });
}

这将更新状态中的regionId。

在App.js中,您应该返回一个新状态:

在PageOne.js中,只需执行以下操作:

changeRegion = (regId) => {
  // How to add/dispatch the regId to the prop 
  this.props.dispatch({ type: 'REGIONAL_ID', regionId: regId });
}
这将更新状态中的regionId