<Provider> 不支持在使用 componentWillMount 或 componentWillUnMount 时即时更改 `store`
<Provider> does not support changing `store` on the fly when using componentWillMount or componentWillUnMount
不支持即时更改 store
。您看到此错误很可能是因为您更新到 Redux 2.x 和 React Redux 2.x,它们不再自动热重载减速器
当我使用 componentWillMount 和 componentWillUnMount 时出现此错误
import React, { Component } from 'react';
import { View, NetInfo, Image } from 'react-native';
import { Container, Text } from 'native-base';
import { RootNavigator } from './src/root';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
import resducers from './src/reducers/index';
export default class App extends Component<Props> {
constructor(Props){
super(Props);
this.state={
connection:null,
}
}
componentWillMount(){
NetInfo.isConnected.addEventListener("connectionChange",this.handleConnectionChange);
NetInfo.isConnected.fetch().done((isConnected)=>this.setState({connection:isConnected}));
}
componentWillUnMount(){
NetInfo.isConnected.removeEventListener("connectionChange",this.handleConnectionChange);
}
handleConnectionChange=(isConnected)=>{
this.setState({connection:isConnected});
}
handeView(){
if(this.state.connection!==null && this.state.connection){
return <RootNavigator />
}else {
return <View style={{flex:1, flexDirection:"row", alignItems:"center", justifyContent:"center"}}>
<Image source={require("./images/connection.gif")} style={{height: 150, width: 150, resizeMode : "stretch"}}/>
</View>
}
}
render() {
return (
<Provider store={createStore(resducers)}>
<Container>
{this.handeView()}
</Container>
</Provider>
);
}
}
每次您的组件呈现时,都会创建一个新商店。
尝试在您的组件之外创建您的商店。
import resducers from './src/reducers/index';
const store = createStore(resducers);
--
<Provider store={store}>
不支持即时更改 store
。您看到此错误很可能是因为您更新到 Redux 2.x 和 React Redux 2.x,它们不再自动热重载减速器
当我使用 componentWillMount 和 componentWillUnMount 时出现此错误
import React, { Component } from 'react';
import { View, NetInfo, Image } from 'react-native';
import { Container, Text } from 'native-base';
import { RootNavigator } from './src/root';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
import resducers from './src/reducers/index';
export default class App extends Component<Props> {
constructor(Props){
super(Props);
this.state={
connection:null,
}
}
componentWillMount(){
NetInfo.isConnected.addEventListener("connectionChange",this.handleConnectionChange);
NetInfo.isConnected.fetch().done((isConnected)=>this.setState({connection:isConnected}));
}
componentWillUnMount(){
NetInfo.isConnected.removeEventListener("connectionChange",this.handleConnectionChange);
}
handleConnectionChange=(isConnected)=>{
this.setState({connection:isConnected});
}
handeView(){
if(this.state.connection!==null && this.state.connection){
return <RootNavigator />
}else {
return <View style={{flex:1, flexDirection:"row", alignItems:"center", justifyContent:"center"}}>
<Image source={require("./images/connection.gif")} style={{height: 150, width: 150, resizeMode : "stretch"}}/>
</View>
}
}
render() {
return (
<Provider store={createStore(resducers)}>
<Container>
{this.handeView()}
</Container>
</Provider>
);
}
}
每次您的组件呈现时,都会创建一个新商店。 尝试在您的组件之外创建您的商店。
import resducers from './src/reducers/index';
const store = createStore(resducers);
--
<Provider store={store}>