相关疑难解决方法(0)

React-redux组件不会在存储状态更改时重新呈现

我今天说要学习反应和减少,但我无法弄清楚如何在状态改变后迫使组件重新渲染.

这是我的代码:

const store = createStore(loginReducer);
export function logout() { return {type: 'USER_LOGIN'} }
export function logout() { return {type: 'USER_LOGOUT'} }
export function loginReducer(state={isLogged:false}, action) {
  switch(action.type) {
    case 'USER_LOGIN':
      return {isLogged:true};
    case 'USER_LOGOUT':
      return {isLogged:false};
    default:


         return state;
      }
    }

    class App extends Component {

      lout(){
        console.log(store.getState()); //IT SHOW INITIAL STATE
        store.dispatch(login());
        console.log(store.getState()); //IT SHOWS THAT STATE DID CHANGE
      }

      ////THIS IS THE PROBLEM, 
    render(){
    console.log('rendering')
    if(store.getState().isLogged){
      return (<MainComponent store={store} />);
    }else{
      return (
        <View style={style.container}>
          <Text onPress={this.lout}> …
Run Code Online (Sandbox Code Playgroud)

reactjs react-native redux react-redux

14
推荐指数
2
解决办法
3万
查看次数

标签 统计

react-native ×1

react-redux ×1

reactjs ×1

redux ×1