Reactjs 无法从combineReducer获取另一个组件中的更新状态值
我正在使用combineReducer来存储状态,它在同一个模块中工作,但是当我在另一个组件中使用它时,它对我不起作用,我在这里添加了我的代码,请任何人检查代码并帮助我解决这个问题?任何帮助都将不胜感激 ProfileView(工作模式) ProfileState.jsReactjs 无法从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';
// 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;
}
}