gpt4 book ai didi

javascript - 如何在流程中输入 react-redux connect?

转载 作者:行者123 更新时间:2023-11-29 23:13:32 26 4
gpt4 key购买 nike

这就是我的 mapStateToProps 的样子。

const mapStateToProps = (state): StateProps => {
let status = false;
if (state.productsPage.currentProduct) {
if (state.productsPage.currentProduct.status === "ACTIVE") {
status = true;
}
}
return {
showModal: state.productsPage.showModal,
currentProduct: state.productsPage.currentProduct,
isLoading: state.status.loading.PRODUCTS_EDIT,
initialValues: {
name: state.productsPage.currentProduct ? state.productsPage.currentProduct.name : "",
status,
},
};
};

这是 StateProps 的形状

type StateProps = {
showModal: boolean,
currentProduct: Object,
isLoading: boolean,
initialValues: {
name: string,
status: boolean,
}
}

这是我对连接的用法。

const connected = connect<React$StatelessFunctionalComponent<any>, StateProps>(mapStateToProps, mapDispatchToProps);

这会产生以下错误,我不知道这意味着什么或如何解决它。

[flow] Cannot call connect because property currentProduct is missing in React.StatelessFunctionalComponent [1] in the indexer property's key of type argument ST. (References: [1])

最佳答案

建议您将 Flow 至少升级到 0.89 以上,并使用 Flow Typed's newest React Redux library definition .

然后,您可以使用PropsOwnProps 注释连接的组件>

import * as React from 'react'

type OwnProps = {|
passthrough: string,
forMapStateToProps: string
|}

type Props = {|
...OwnProps,
fromMapStateToProps: string,
dispatch1: () => void
|}

const MyComponent = (props: Props) => (
<div onClick={props.dispatch1}>
{props.passthrough}
{props.fromMapStateToProps}
</div>
)

export default connect<Props, OwnProps, _, _, _, _>(
mapStateToProps,
mapDispatchToProps
)(MyComponent)

Here是一份更详细的指南,其中包含更多用例。

关于javascript - 如何在流程中输入 react-redux connect?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53397055/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com