Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/464.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在流程中键入react redux connect?_Javascript_Reactjs_React Redux_Flowtype - Fatal编程技术网

Javascript 如何在流程中键入react redux connect?

Javascript 如何在流程中键入react redux connect?,javascript,reactjs,react-redux,flowtype,Javascript,Reactjs,React Redux,Flowtype,这就是我的MapStateTrops的外观 const mapStateToProps = (state): StateProps => { let status = false; if (state.productsPage.currentProduct) { if (state.productsPage.currentProduct.status === "ACTIVE") { status = true; }

这就是我的
MapStateTrops
的外观

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,
    }
}
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)
这是我对connect的用法

const connected = connect<React$StatelessFunctionalComponent<any>, StateProps>(mapStateToProps, mapDispatchToProps);
const connected=connect(mapStateToProps、mapDispatchToProps);
这会产生以下错误,我不知道这意味着什么,也不知道如何着手解决它

[flow]无法调用
connect
,因为属性
currentProduct
无效 索引器中的
React.StatelessFunctionalComponent
[1]中缺少 属性的键的类型为参数
ST
。(参考文献:[1])


React$StatelessFunctionalComponent
是一个需要prop类型的泛型。而不是


您可能需要连接,而不是提供元素类型。

建议您将流升级到至少超过0.89,然后使用

然后,您可以使用
Props
OwnProps

type StateProps = {
    showModal: boolean,
    currentProduct: Object,
    isLoading: boolean,
    initialValues: {
        name: string,
        status: boolean,
    }
}
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)
import*作为来自“React”的React
类型OwnProps={|
passthrough:string,
FormPStateToprops:字符串
|}
类型道具={|
…拥有道具,
FromMapStateTrops:string,
dispatch1:()=>无效
|}
常量MyComponent=(道具:道具)=>(
{props.passthrough}
{props.fromMapStateToProps}
)
导出默认连接(
MapStateTops,
mapDispatchToProps
)(MyComponent)

是一个更详细的指南,包含了更多的用例。

不确定任何vs-prop类型,您可能很快就会知道,但是
connect
泛型中的第一个参数必须有一个可调用的签名,至少在我使用的react-redux flow-typed版本中是这样。