本文介绍了使用 redux 命名导出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经习惯使用命名导出,因为它使重构的工作更轻松.我刚刚开始实现 redux,但似乎我无法进行命名导出,因为连接需要映射组件.

i have got used to using named exports as it makes life easier for refactoring. I have just started to implement redux but it seems i can't do a named export because the connect needs to map the component.

例如

class Something extends Component { ... }

export default connect(mapStateToProps)(Something);

是否可以使用像Something"这样的命名导出,我不能将导出放在类上,因为尽管 react 继续工作 - 连接没有被导出,所以没有 redux 状态

Would it be possible to use a named export like "Something", i can't place the export on the class as although react continues to work - the connect is not getting exported so there is no redux state

有什么想法吗?

提前致谢

推荐答案

只需将其分配给一个常量并像这样导出:

Just assign it to a const and export that like so:

class Something extends Component { ... }

export const ConnectedSomething = connect(mapStateToProps)(Something);

然后你可以像这样导入它:

Then you can import it like so:

import { ConnectedSomething } from './....'

这篇关于使用 redux 命名导出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 18:47