简体   繁体   中英

React component not getting redux's initial state set by reducer

While creating the reducer, i have set the initial state but while loading the component for the first time, i am getting an empty state.

 reducer file - const initialValues = { geo: { latitude: 0, longitude: 0 } } const emp = (state = initialValues, action) => { switch (action.type) { case 'bike': { return {...state, data: action.payload } } case 'car': { return {...state, headers: action.payload } } default: return state } } component file- export default function Emp() { const emp = useSelector(state => state) console.log('emp state', emp) } index.js const store = createStore(reducer, {}, compose( applyMiddleware( loggingMiddleware, ), window.devToolsExtension? window.devToolsExtension(): f => f ) )

I got the solution. Actually i was not using combine reducer before thats why reducer's state was not getting initialized.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM