SomeAction 不是函数。 (在“SomeAction()”中,“SomeAction”未定义)。
当我执行 SomeAction 函数时,出现此错误。
如果我的 Action 文件中只有 SomeAction 并且我这样做
export default SomeAction;
然后按如下方式导入
import SomeAction from 'path/to/action'
效果很好。但由于我想要多个功能,所以我执行了以下操作。
这是我的 Actions.js
const SomeAction = () => dipatch => ({
// Code here
});
const AnotherAction = () => dispatch => ({
// Code here
});
export default { SomeAction, AnotherAction };
然后在我的 App.js 中
import { SomeAction } from 'path/to/action';
// Here the eslint gives me an error -> 'SomeAction not found in "path/to/action"'
const App = ({ SomeAction }) => {
// Code here
};
App.propTypes = {
SomeAction: PropTypes.func,
}
const mapStateToProps = state => ({
error: state.user.error,
});
export default connect(
mapStateToProps,
{ SomeAction }
)(App);
这适用于我正在编码的 React Web 应用程序。为什么不在 React-Native 中呢?
最佳答案
查看,我发现您默认导出两种方法。正常实现是一种方法。另一种解决方案是逐个导出方法并使用其名称导入它们。
导出示例:
export const SomeAction = () => dipatch => ({
// Code here
});
export const AnotherAction = () => dispatch => ({
// Code here
});
导入示例:
import { SomeAction, AnotherAction } from 'path/to/action';
此示例是导出和导入函数的正常方式。
您不能导出两个默认方法。
关于javascript - React-native 和 redux 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57202195/