如果从组件连接到单独的文件中,则不传递道具?

问题描述 投票:0回答:1

在我的文件夹中,我有这个结构

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接收道具。我不确定这是问题所在,所有帮助将不胜感激。

reactjs redux
1个回答
0
投票

如果您不仅需要访问操作,还需要访问Component中的redux状态,那么mapStateToProps也应转到connect-而不是null

© www.soinside.com 2019 - 2024. All rights reserved.