在已导出类的组件中进行redux导出

时间:2018-08-27 21:38:25

标签: react-native react-redux export dispatcher

我有一个本机组件类别定义为export:

export default class Splash extends React.Component {

我想将Splash类连接到redux存储,以便在props中获得redux状态(或者我是否误解了这个概念?),以便可以通过setState方法调度动作。

我在Splash.js中定义了mapStateToPropsmapDispatchToProps(或者我在这里也弄错了吗?)

所以我想做

export default reduxConnect(mapStateToProps, mapDispatchToProps)(Splash);

但是它已经被导出了。我应该更改export行之一吗?我是否需要使用reduxConnect来获取具有状态的道具,并使用setState调度程序方法?

1 个答案:

答案 0 :(得分:0)

您可以通过以下方式完成

import {connect} from 'react-redux'

class Splash extends React.Component {
  ... rest of the code
  ... dispatch by referencing props from the connector
}

const mapStateToProps = state = ({
   ... bind props to the store values here
})

 const mapDispatchToProps = dispatch = ({
   ... dispatch the actions here
})

export default connect(mapStateToProps, mapDispatchToProps)(Splash)

我建议您在文档here

中查看示例
相关问题