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

Cha*_*man 5 javascript reactjs flowtype react-redux

这就是我的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,
        },
    };
};
Run Code Online (Sandbox Code Playgroud)

这是形状StateProps

type StateProps = {
    showModal: boolean,
    currentProduct: Object,
    isLoading: boolean,
    initialValues: {
        name: string,
        status: boolean,
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我对连接的用法。

const connected = connect<React$StatelessFunctionalComponent<any>, StateProps>(mapStateToProps, mapDispatchToProps);
Run Code Online (Sandbox Code Playgroud)

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

[flow] 无法调用,因为类型为 argument 的索引器属性的键 [1] 中缺少connect属性。(参考文献:[1])currentProductReact.StatelessFunctionalComponentST

Cha*_*ver 0

React$StatelessFunctionalComponent是一个需要 prop 类型的泛型。而不是<any>,您会想要该函数期望接收的 props - 最重要的是,它期望接收您StateProps返回的mapStateToProps(尽管它可能还期望其他)。

它可能会根据 的版本而变化react-redux,但我看到一些文档表明 的泛型connect是 的返回值mapStateToProps,而不是 React 元素。-来源

您可能需要connect<StateProps, DispatchPropsIfAny>而不是提供元素类型。