0
votes

I have a parent component and i want to send data to it's child component.

I tried using the react method of passing the data but got error.

Error:

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

Below is the code

Parent file:

<Modern pdata={this.state.length} />

Child file:

import * as React from "react";
export default class Modern extends React.Component {
  constructor(props) {
    super(props);
  }

  render() {
    return (
      <div>
        <p>Hello Modern {this.props.pdata}</p>
      </div>
    );
  }
}
2
Just to confirm you are using typescript? - Yogender Singh
yeah i'm using typescript ver 2.9.2 - user8535404

2 Answers

0
votes

React is spfx uses typescript . so you need to create a interface for the props .

interface ModernProps {
pdata: number;
}

export default class Modern extends React.Component<ModernProps>
0
votes

link to document explaining the reason for this issue in case you are interested