在我的文件夹中,我有这个结构
Component.tsx
connect.ts
index.ts
在用于连接的单独文件中
import { connect } from 'react-redux'
import { actions } from '../../redux/actions';
import Component from './Component';
const mapStateToProps = (state: any/*, ownProps*/) => { }
const mapDispatchToProps = { actions }
export default connect(
null,
mapDispatchToProps
)(Component)
[Component
是我要使用props.actions
的组件
索引中
export { default } from './connect';
然后,我想这样导入,从而在另一个组件中使用此组件
import FormComponent from './components/Form';
但是我的组件无法从connect接收道具。我不确定这是问题所在,所有帮助将不胜感激。
如果您不仅需要访问操作,还需要访问Component
中的redux状态,那么mapStateToProps
也应转到connect
-而不是null
。