Store does not have a valid reduce & useSelector returns undefined state
See original GitHub issueHello fellas!
Thank you for your help in advance!
I am facing a very odd problem with my React Native app, with my store not accepting the reducers I pass from Slice function. Would appreciate any insight on this!
Edit: Console logs the following error: Store does not have a valid reducer. Make sure the argument passed to combineReducers is an object whose values are reducers.
App.js
import {enableES5} from 'immer';
enableES5();
import AppNavigator from './routes/app.navigator';
import { Provider } from 'react-redux';
import poiReducer from './poistate';
import { configureStore } from '@reduxjs/toolkit';
import { AppRegistry } from 'react-native';
export default function App() {
AppRegistry.registerComponent('main',() => App);
const store1 = configureStore({
reducer: { loc: poiReducer }
});
return(
<Provider store={store1}><AppNavigator/></Provider>
)
PoiState.js
import { createSlice } from "@reduxjs/toolkit";
import { createAsyncThunk } from "@reduxjs/toolkit";
export const getPoi = createAsyncThunk(
'poi/getPoi',
async () => {
console.log('here');
const response = await fetch('https://warply.s3.amazonaws.com/data/test_pois.json')
const format = await response.json();
return format;
}
);
export const poiSlice = createSlice({
name: 'poi',
initialState:{
poi:[],
isLoading: false,
},
extraReducers:{
[getPoi.pending]:(state)=>{
state.isLoading = true;
},
[getPoi.fulfilled]:(state, action)=>{
state.loc= action.payload;
state.isLoading = true;
},
[getPoi.rejected]:(state)=>{
state.isLoading = false;
},
},
});
export default poiSlice.reducer;
Issue Analytics
- State:
- Created a year ago
- Comments:5
Top Results From Across the Web
UseSelector State is Undefined - Stack Overflow
Sometimes having a break in the switch block of the reducer can cause the prop not defined in the state.
Read more >Why is my useSelector returning undefined but my state is ...
The whole point of a reducer is that it returns a new state and does not touch the old one. Redux only looks...
Read more >Hooks - React Redux
When an action is dispatched, useSelector() will do a reference comparison of the previous selector result value and the current result value.
Read more >Getting Data Out of the Redux Store with Selectors
A selector is a pure function that takes a state object from the Redux store and returns some information extracted from that state...
Read more >cannot read properties of undefined (reading 'type') redux
useSelector allows you to extract data from the Redux store state, ... So, looks like item.id === Number(photo_id) is probably not resolving to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@KrowNFL I think you’ve got multiple problems going on here, unfortunately 😦
poistate
in the root . That may be confusing the imports.export default poiSlice.reducer
inpoistate.js
, which exports just the reducer by itself. That part is good. But:import poiSlice from './poistate'
inApp.js
, so conceptually the name is wrong - it’s not the “slice object”, it’s the “slice reducer”console.log(poiSlice.reducer)
inApp.js
, which isn’t right because you didn’t import the entire sliceconfigureStore({reducer: { loc: poiReducer }})
, but there isn’t apoiReducer
variable in this file because you didn’t give it that name when you imported frompoistate
<App>
, which isn’t goodSo, tbh you’ve got some very confused code, and none of this is a Redux-specific problem. You’re mismatching import names and variables and values, and none of this is lining up correctly.
I’d recommend looking at the repo I linked above, and using that as a guideline for setting up the project.
Certainly
https://github.com/KrowNFL/Warply