Вопрос

child component

export default class Example extends React.Component<ICState,{sData,cData}> {
constructor(props,state:ICState) {
        super(props);
        sp.setup({
            context: this.props.cData
        });

       
        this.state = {
            arr:[]
          };
        
    }
}

Parent Component

<Example sData="someData" cData={this.props.context}/>

If i use State for the child component along with sData and cData i am unable to use child state ICState. Could anyone please let me know where i am going wrong?

Error Message in Parent component

Type '{ sData: any; cData: any; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly & Readonly<{ children?: ReactNode; }>'. Property 'sData' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly & Readonly<{ children?: ReactNode; }>'

Это было полезно?

Решение

React.Component typings take props type as first parameter, so you just need to swap them :

export default class Example extends React.Component<{sData,cData}, ICState>

Лицензировано под: CC-BY-SA с атрибуция
Не связан с sharepoint.stackexchange
scroll top