1

I want to call SPFX react child component from parent component . But I am getting error while creating react component .

Error:

Declaration or statement expected. Cannot find name 'div'. Type 'boolean' is not assignable to type 'ReactElement'.

Child Component:

export interface IDCLabelProps {
    thisCount: number;
    parenIid :number;
  }



    export default class ShopingCart extends React.Component<
    IDCLabelProps,any,any> 
{
      public constructor(props: IDCLabelProps, state: IDCLabelProps) {
        super(props);


      public render(): React.ReactElement<IDCLabelProps> {
        return (
          <div className={styles.shopingCart}>

          </div>
        );
      }
    }

How can I fix this ? Please help .

1 Answer 1

3

I see two issues:

  1. You need to close your constructor
   public constructor(props: IDCLabelProps, state: IDCLabelProps) {
      super(props);
    }
  1. You probably named your component file YourComponentName.ts -- with a .ts extension. Rename your file to YourComponentName.tsx and it should magically start working.

I hope this helps?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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