Reactjs React Native-(0,_redux.combineReducers)不是函数
我目前正在学习React Native中的一些redux。但是,如果我试图在index.js文件中组合我的减缩器,我就会遇到一个错误Reactjs React Native-(0,_redux.combineReducers)不是函数,reactjs,react-native,redux,react-redux,reducers,Reactjs,React Native,Redux,React Redux,Reducers,我目前正在学习React Native中的一些redux。但是,如果我试图在index.js文件中组合我的减缩器,我就会遇到一个错误 (0, _redux.combineReducers) is not a function 我看了一些关于如何使用它的教程,我遵循每一步,但它一直出现在我的屏幕上 我的App.js如下所示: import React, { Component } from 'react'; import { Platform, StyleSheet, Text, View }
(0, _redux.combineReducers) is not a function
我看了一些关于如何使用它的教程,我遵循每一步,但它一直出现在我的屏幕上
我的App.js如下所示:
import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View } from 'react-native';
import ReduxThunk from 'redux-thunk';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
import reducers from './reducers/reducers';
import { Header } from './components/common/Header';
let store = createStore(reducers, applyMiddleware(ReduxThunk));
export default class App extends Component {
render() {
return (
<Provider store={ store }>
<View style={ styles.container }>
<Header title="Tech Stack"/>
</View>
</Provider>
);
}
}
LibraryReducer.js
import data from '../data/LibraryList.json';
export default () => data;
Console errors:
[Error log][1]
数据json:
[
{
"id": 0,
"title": "React",
"description": "JS framework"
},
{
"id": 1,
"title": "Vue",
"description": "JS framework"
},
{
"id": 2,
"title": "Angular",
"description": "JS framework"
}
]
package.json
{
"name": "redux",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "16.6.1",
"react-native": "0.57.5",
"react-redux": "^5.1.1",
"redux": "^4.0.1",
"redux-thunk": "^2.3.0"
},
"devDependencies": {
"babel-jest": "23.6.0",
"jest": "23.6.0",
"metro-react-native-babel-preset": "0.49.2",
"react-test-renderer": "16.6.1"
},
"jest": {
"preset": "react-native"
}
}
谢谢大家的建议
已解决:
启动了一个新项目,但没有给它命名为redux本身。我们看了很多不同的东西,但问题在于模块分辨率<代码>从'redux'导入{combineReducers}不起作用,显然是因为项目本身在package.json文件中被命名为'redux',或者是因为项目根目录中的一个文件夹被命名为'redux'。我们看了很多不同的东西,但问题在于模块解析<代码>从'redux'导入{combineReducers}不起作用,显然是因为项目本身在其package.json文件中被命名为'redux',和/或因为项目根目录中的一个文件夹被命名为'redux'。所以首先我会在您的项目文件夹上安装ReduxThunk,所以运行以下命令:
npm i redux-thunk --save
接下来在你的App.js
中,像这样导入这个库
import ReduxThunk from 'redux-thunk'
然后创建Redux存储
const store = createStore(reducers, applyMiddleware(ReduxThunk))
创建reducers函数的方法应该在reducers.js
文件的末尾,如下所示
const reducers = combineReducers({
libraries,
//otherFunctions...
});
export default reducers;
不要忘记在reducers.js
文件中从redux导入combineReducers方法
import { combineReducers } from 'redux';
combineReducers方法接受您先前在reducers.js
中声明的函数,用于以下expample(im编写…)
您应该能够根据需要为switch
语句编写许多案例。例如
const INITIAL_STATE = { isLoggedIn: false }
function libraries(state = INITIAL_STATE, action){
switch (action.type) {
case "isLogginSuccess":
return {...state, isLoggedIn: action.payload}
default:
return state
}
}
应该通过在所需组件中调用另一个函数来触发减速器案例“isLogginSuccess” 首先,我会在您的项目文件夹中安装Reduxtunk,所以请运行以下命令:
npm i redux-thunk --save
接下来在你的App.js
中,像这样导入这个库
import ReduxThunk from 'redux-thunk'
然后创建Redux存储
const store = createStore(reducers, applyMiddleware(ReduxThunk))
创建reducers函数的方法应该在reducers.js
文件的末尾,如下所示
const reducers = combineReducers({
libraries,
//otherFunctions...
});
export default reducers;
不要忘记在reducers.js
文件中从redux导入combineReducers方法
import { combineReducers } from 'redux';
combineReducers方法接受您先前在reducers.js
中声明的函数,用于以下expample(im编写…)
您应该能够根据需要为switch
语句编写许多案例。例如
const INITIAL_STATE = { isLoggedIn: false }
function libraries(state = INITIAL_STATE, action){
switch (action.type) {
case "isLogginSuccess":
return {...state, isLoggedIn: action.payload}
default:
return state
}
}
应该通过在所需组件中调用另一个函数来触发减速器案例“isLogginSuccess” 看起来你和我有同样的问题
TLDR:将您调用的
redux
文件夹重命名为其他文件夹,擦除节点\u模块
并重新安装,它应该可以工作 看起来你和我有同样的问题
TLDR:将您调用的
redux
文件夹重命名为其他文件夹,擦除节点\u模块
并重新安装,它应该可以工作 今天我遇到了同样的问题,很幸运我很快就解决了这个问题,所以我要在这里添加这个!在我的构建中出现此错误的原因是因为我使用了babel模块分解器插件,并且我命名了我的一个模块分解器redux,我将在这里添加此错误,因为我今天遇到了相同的问题,幸运的是我很快就解决了这个问题!在我的构建中出现此错误的原因是因为我使用了babel模块解析器插件,并且我将我的模块解析器之一命名为redux,您收到的是相同的错误,还是不同的错误?相同的错误。第一次(热重新加载后)我得到错误对象。非对象的defineProperty被调用,但当我手动刷新模拟器时,我得到了与以前相同的结果。感谢编辑,但我仍然得到相同的消息。尝试一下-将redux
文件夹重命名为store
。这可能是一个名称冲突问题。仍然没有运气:/folder structure:src/reducer您收到的是相同的错误,还是不同的错误?相同的错误。第一次(热重新加载后)我得到错误对象。非对象的defineProperty被调用,但当我手动刷新模拟器时,我得到了与以前相同的结果。感谢编辑,但我仍然得到相同的消息。尝试一下-将redux
文件夹重命名为store
。这可能是名称冲突问题。仍然没有运气:/folder structure:src/reducers@PeeJee您安装了哪个版本的redux?共享package.json文件的图片please@PeeJee一切看起来都很好。请添加index.js文件和所有其他组件(如App.js和reducers.js)中的代码,好吗!已进行更改。@PeeJee尝试从还原程序中删除所有console.log。js@PeeJee在您的reducers.js中,更改如下constreducers=combineReducers({libraries=()=>{},})代码>@PeeJee您安装了哪个版本的redux?共享package.json文件的图片please@PeeJee一切看起来都很好。请添加index.js文件和所有其他组件(如App.js和reducers.js)中的代码,好吗!已进行更改。@PeeJee尝试从还原程序中删除所有console.log。js@PeeJee在您的reducers.js中,更改如下constreducers=combineReducers({libraries=()=>{},})代码>仍然不成功:/撤消重命名后,尝试将代码合并到未断开的分支中。我遇到了这个问题,这为我解决了问题,尽管我不知道如何解决。仍然没有成功:/撤消重命名后,尝试将代码合并到未断开的分支中。我有这个问题,这为我解决了它,尽管我不知道如何解决。