I'm new in redux I'm trying to connect redux with react native when I set all and In App.js i add <provider store={store}>
it display me that error:
TypeError: (0, _$$_REQUIRE(_dependencyMap[0], "redux").createStore) is not a function.
App.js
import { Counter } from './assets/counter';
import { Provider } from 'react-redux';
import {store} from './assets/store/store'
const App= (props) => {
return (
<View style={{flex:1}}>
<Provider store={store} >
<Counter/>
</Provider>
</View>
);
};
export default App;
cunter.js
export const Counter = (props) =>{
return(
<View style={{flex:1,justifyContent:'center', alignItems:'center'}} >
<Button title="Add Inc" />
<Text>Counter</Text>
<Button title="Add Dec" />
</View>
)
}
store.js
import {createStore} from 'redux'
import {mainReducer} from './reducers'
export const store = createStore(mainReducer)
reducer.js
import {ADDITION, SUBTRACTION} from './actionType'
const initialState = {
counter:0
}
export const mainReducer=(state=initialState, action)=>{
switch (action.type) {
case ADDITION:
return {...state, counter:state.counter+1}
case SUBTRACTION:
return {...state, counter:state.counter-1}
default:
return state
}
}
package.json
"dependencies": {
"react": "17.0.1",
"react-native": "0.64.2",
"react-redux": "^7.2.4",
"redux": "^4.1.1"
},
I'm new in redux I'm trying to connect redux with react native when I set all and In App.js i add <provider store={store}>
it display me that error:
TypeError: (0, _$$_REQUIRE(_dependencyMap[0], "redux").createStore) is not a function.
App.js
import { Counter } from './assets/counter';
import { Provider } from 'react-redux';
import {store} from './assets/store/store'
const App= (props) => {
return (
<View style={{flex:1}}>
<Provider store={store} >
<Counter/>
</Provider>
</View>
);
};
export default App;
cunter.js
export const Counter = (props) =>{
return(
<View style={{flex:1,justifyContent:'center', alignItems:'center'}} >
<Button title="Add Inc" />
<Text>Counter</Text>
<Button title="Add Dec" />
</View>
)
}
store.js
import {createStore} from 'redux'
import {mainReducer} from './reducers'
export const store = createStore(mainReducer)
reducer.js
import {ADDITION, SUBTRACTION} from './actionType'
const initialState = {
counter:0
}
export const mainReducer=(state=initialState, action)=>{
switch (action.type) {
case ADDITION:
return {...state, counter:state.counter+1}
case SUBTRACTION:
return {...state, counter:state.counter-1}
default:
return state
}
}
package.json
"dependencies": {
"react": "17.0.1",
"react-native": "0.64.2",
"react-redux": "^7.2.4",
"redux": "^4.1.1"
},
Share
Improve this question
edited Aug 17, 2021 at 13:23
Adil Ijaz
asked Aug 17, 2021 at 13:03
Adil IjazAdil Ijaz
1352 silver badges13 bronze badges
3 Answers
Reset to default 2i have same problem but its solved and i just want to share.. its all happen because "npx react-native init Redux" well i try to create another react-native init with different name and move all folder from old one that i named it "Redux" then its all running normal.. so do not try to create folder or event project name with same modul thats we installed via NPM.. hope its help and enjoy your day.. thank you..
For anyone running into a similar issue - I fixed this by removing a dependancy cycle in my import statements.
E.g. A
imports from B
imports from A
.
I had to move the function I was importing from A
into file B
(so B
did not import from A
).
I solved it with the help of a previous ment finding that the reason has something to do with:
its all happen because "npx react-native init Redux"
I assume that namespace will be used by redux toolkit in runtime. I had a path alias mapping my redux actions and reducers to @redux which seems to take same symlink space. The prev. reply is one of the most underrated ments on stack overflow.