Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 无法从combineReducer获取另一个组件中的更新状态值_Reactjs_React Native_React Redux_Reducers - Fatal编程技术网

Reactjs 无法从combineReducer获取另一个组件中的更新状态值

Reactjs 无法从combineReducer获取另一个组件中的更新状态值,reactjs,react-native,react-redux,reducers,Reactjs,React Native,React Redux,Reducers,我正在使用combineReducer来存储状态,它在同一个模块中工作,但是当我在另一个组件中使用它时,它对我不起作用,我在这里添加了我的代码,请任何人检查代码并帮助我解决这个问题?任何帮助都将不胜感激 ProfileView(工作模式) ProfileState.js // Initial state const initialState = { email : '' }; // Actions const SET_LOGIN = 'ProfileState/SET_LOGIN';

我正在使用combineReducer来存储状态,它在同一个模块中工作,但是当我在另一个组件中使用它时,它对我不起作用,我在这里添加了我的代码,请任何人检查代码并帮助我解决这个问题?任何帮助都将不胜感激

ProfileView(工作模式)

ProfileState.js

// Initial state
const initialState = {
  email : ''
};

// Actions
const SET_LOGIN = 'ProfileState/SET_LOGIN';


export function doLogin(username) {
  return {
    type: SET_LOGIN,
    email:username
  };
}


// Reducer
export default function ProfileStateReducer(state = initialState, action = {}) {
  console.log(action.type);
  switch (action.type) {
    case SET_LOGIN:
      return Object.assign({}, state, {
        email: action.email,
      }); 
    default:
      return state;
  }
}
import { createStore } from 'redux'
import reducer from '../../redux/reducer' 
export default function HomeScreen({ isExtended, setIsExtended }) {

  function getdata() {
    console.log("sdsdsd");
    const store = createStore(reducer);
    store.subscribe(() => {
      console.log('subscribed for home counter actions', store.getState().profile);
    });
  }  

  return (
    <View style={styles.container}>
      <ImageBackground
        source={require('../../../assets/images/background.png')}
        style={styles.bgImage}
        resizeMode="cover"
      >
        <View style={styles.section}>
          <Text size={20} white onPress = {getdata}>
            Home
          </Text>
        </View>
       </ImageBackground>
    </View>
  );
}
import { combineReducers } from 'redux';

// ## Generator Reducer Imports
import gallery from '../modules/gallery/GalleryState';
import profile from '../modules/profile/ProfileState';
import app from '../modules/AppState';
import calendar from '../modules/calendar/CalendarState';

export default combineReducers({
  // ## Generator Reducers
  gallery,
  app,
  calendar,
  profile
});
// Initial state
const initialState = {
  email : ''
};

// Actions
const SET_LOGIN = 'ProfileState/SET_LOGIN';


export function doLogin(username) {
  return {
    type: SET_LOGIN,
    email:username
  };
}


// Reducer
export default function ProfileStateReducer(state = initialState, action = {}) {
  console.log(action.type);
  switch (action.type) {
    case SET_LOGIN:
      return Object.assign({}, state, {
        email: action.email,
      }); 
    default:
      return state;
  }
}