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

Viewed 33

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
  )
)

1 Answers

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

Related