我有一个需要在(this.props.dispatch)中调用调度的组件,但调度不存在,因此我决定添加到我的组件的连接,但这样做时出现错误。当我的应用程序中的其他组件也有连接并且不这样做时,我无法弄清楚为什么添加连接会引发错误。如果我删除连接线,错误就会消失。有谁知道为什么我会收到此错误?
export default class ItemsInCartContent extends Component {
constructor(props) {
super(props);
this.state = {
active: null,
products: props.products,
ascending: true,
sortIcon: 'unsorted',
sortIconStyle: styles.sortIcon
};
this.props.dispatch(getOrderDetails(this.props.orderId));
}
render() {
const cartIcon = (<Icon name="shopping-cart" style={styles.cartIcon} />);
const sortIcon = (<Icon name={this.state.sortIcon} style={this.state.sortIconStyle} />);
return (
<View style={styles.itemsInCartContent}>
</View>
);
}
}
function mapStateToProps(state) {
const {products} = state;
return {
products
};
}
export default connect(mapStateToProps)(ItemsInCartContent);
最佳答案
如果你仔细阅读日志,错误就非常清楚了:
... SyntaxError ... only one default export allowed per module ...
你有
export default class ItemsInCartContent extends Component {
和
export default connect(mapStateToProps)(ItemsInCartContent);
这些导出中只有一个可以是默认
。
我建议完全删除 ItemsInCartContent
上的导出,因为该组件应该与 connect
一起使用,或者明确说明:
export class ItemsInCartContent extends Component {
关于javascript - 为什么我不能在 React Native 组件中使用 connect ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49573929/