0

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; }>'

1

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.