Javascript 在Redux React Native中使用还原程序时导入/导出
我正在用React Native学习Redux,我有一个这样的例子:Javascript 在Redux React Native中使用还原程序时导入/导出,javascript,reactjs,react-native,redux,Javascript,Reactjs,React Native,Redux,我正在用React Native学习Redux,我有一个这样的例子: import {someFumnction} from './nameOfFile' import someFunction from './nameOfFile' reducer.js createStore.js 它工作正常,但我不明白为什么我必须在reducer.js中使用export default 当我尝试使用 // reducer.js export makeRootReducer 及 它不起作用 请帮
import {someFumnction} from './nameOfFile'
import someFunction from './nameOfFile'
reducer.js
createStore.js
它工作正常,但我不明白为什么我必须在reducer.js中使用
export default
当我尝试使用
// reducer.js
export makeRootReducer
及
它不起作用
请帮我详细解释一下
非常感谢。您指的是命名导出和默认导出 命名导出的示例:
export const someFunction = () => {
// some code here...
}
现在,您可以将其导入另一个文件,如下所示:
import {someFumnction} from './nameOfFile'
import someFunction from './nameOfFile'
但如果你这样做了:
export default function someFunction () {
// some code here...
}
这是默认导出,您必须按如下方式导入:
import {someFumnction} from './nameOfFile'
import someFunction from './nameOfFile'
在您的示例中,如果更改此选项:
const makeRootReducer = () => {
return combineReducers({
home
});
};
export default makeRootReducer;
为此:
export const makeRootReducer = () => {
return combineReducers({
home
});
};
它将成为命名导出,而不是默认导出,现在您可以执行以下操作:
import {makeRootReducer} from....
希望澄清。。。这里还有更多的但是当我尝试使用它时,我得到一个错误,比如:TypeError:(0,_reducer.makeRouteReducer)不是一个函数。(在“(0,_reducer.makeRouteReducer)(),“(0,_reducer.makeRouteReducer)”未定义)(0,_reducer.makeRouteReducer)不是一个函数您的代码中有一个输入错误
makeRootReducer
和makeRouteReducer..
@恩圭ễ内华达州ạ这是我的应用程序回购,在我按照你的建议更改后,它仍然不起作用:我找到了它。谢谢你@SakoBu