Reactjs 是否可以在不连接的情况下发送操作? 导出默认类应用程序扩展组件{ ... componentDidMount(){ //注册事件侦听器 BackgroundGeolocation.on('location',this.onLocation,this.onError); } onLocation(位置){ //希望分派操作以更新存储中的变量 } render(){ 返回( ); } }
据我所知,我不可能连接到这个组件中的存储,因为我们只是在配置存储并将其传递给提供者。如何在我的Reactjs 是否可以在不连接的情况下发送操作? 导出默认类应用程序扩展组件{ ... componentDidMount(){ //注册事件侦听器 BackgroundGeolocation.on('location',this.onLocation,this.onError); } onLocation(位置){ //希望分派操作以更新存储中的变量 } render(){ 返回( ); } },reactjs,react-native,redux,react-redux,Reactjs,React Native,Redux,React Redux,据我所知,我不可能连接到这个组件中的存储,因为我们只是在配置存储并将其传递给提供者。如何在我的onLocation事件中分派操作?您可以使用store对象直接分派操作 export default class App extends Component { ... componentDidMount() { //registering event listener BackgroundGeolocation.on('location', this.onLocation, th
onLocation
事件中分派操作?您可以使用store对象直接分派操作
export default class App extends Component {
...
componentDidMount() {
//registering event listener
BackgroundGeolocation.on('location', this.onLocation, this.onError);
}
onLocation(location) {
//wishing to dispatch an action to update variable in store
}
render() {
return (
<Provider store={store}>
<AlertProvider>
<MainNavigator screenProps={{ isConnected: this.state.isConnected }} />
</AlertProvider>
</Provider>
);
}
}
如果您在其他组件中存储对象不可用,请将其从主组件导出并导入到需要的位置,然后使用上面的语句,您可以使用此代码并在类中添加构造函数,如下所示
store.dispatch({type:"UPDATE_VARIABLE", payload:variable.value})
很乐意帮忙。:)您从何处导入“存储”?@Renoldus from
'/redux store'
constructor(props) {
super(props);
}
onLocation() {
this.props.dispatch({type: GET_THINGS_REQUESTED, payload: value});
}