Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.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
Reactjs 有未使用的';合并DPROPS&x27;参数在';连接';组件渲染时引发错误_Reactjs_Typescript_Redux_React Redux - Fatal编程技术网

Reactjs 有未使用的';合并DPROPS&x27;参数在';连接';组件渲染时引发错误

Reactjs 有未使用的';合并DPROPS&x27;参数在';连接';组件渲染时引发错误,reactjs,typescript,redux,react-redux,Reactjs,Typescript,Redux,React Redux,我正在为我当前的Typescript React项目使用Redux,但要进入其中有点困难。不过,到目前为止,连接组件对我来说还不错 interface OwnProps { ownProp?: boolean; } interface PropsFromState { stateProp: any; } interface PropsFromDispatch { dispatchProp: (...) => void; } type MyComponentPr

我正在为我当前的Typescript React项目使用Redux,但要进入其中有点困难。不过,到目前为止,连接组件对我来说还不错

interface OwnProps {
    ownProp?: boolean;
}

interface PropsFromState {
    stateProp: any;
}

interface PropsFromDispatch {
    dispatchProp: (...) => void;
}

type MyComponentProps = OwnProps & PropsFromState & PropsFromDispatch;

class MyComponent extends React.Component<MyComponentProps> {...}

const mapStateToProps = ({ componentState }: IAppState, ownProps: OwnProps): PropsFromState => {
    return {
        stateProp: componentState.stateProp,
        ownProp: ownProps.ownProp,
    };
};

const mapDispatchToProps = (dispatch: any): PropsFromDispatch => {
    return {
        dispatchProp: (...) => dispatch(dispatchProp(...))
    };
};
export default connect<PropsFromState, PropsFromDispatch, OwnProps>(
    mapStateToProps,
    mapDispatchToProps
)(MyComponent);
但是因为我必须将
mergedProps
的第三个参数放在两者之间(我认为可以默认为
null
,没有任何问题),
tslint
现在在我尝试渲染组件时为我抛出一个错误,比如

<MyComponent ownProp ref={ref => this.comp = ref}/>

Type '{ ownProp: true; ref: (ref: Component<Pick<MyComponent, "ownProp" | "stateProp" | "dispatchProp"> & OwnProps, any, any>) => Component<...>; }' is missing the following properties from type 'Readonly<Pick<MyComponentProps, "ownProp" | "stateProp" | "dispatchProp"> & OwnProps>': stateProp, dispatchProp - ts(2739)
this.comp=ref}/>
类型“{ownProp:true;ref:(ref:Component)=>Component;}”缺少类型“Readonly”中的以下属性:stateProp,dispatchProp-ts(2739)

似乎组件现在需要其他不需要的道具。知道如何处理这个问题吗?

在谷歌搜索了很多次之后,我最终导出了连接和未连接的组件,连接用于redux,未连接用于使用ref。这对我来说是可行的,但仍然在寻找一些真正的答案。
<MyComponent ownProp ref={ref => this.comp = ref}/>

Type '{ ownProp: true; ref: (ref: Component<Pick<MyComponent, "ownProp" | "stateProp" | "dispatchProp"> & OwnProps, any, any>) => Component<...>; }' is missing the following properties from type 'Readonly<Pick<MyComponentProps, "ownProp" | "stateProp" | "dispatchProp"> & OwnProps>': stateProp, dispatchProp - ts(2739)