0

I wasn't able to find an answer for this. I'm using TS to build some Components in React, the thing is I'm working with Component Framework and whenever I try to send the props to a Function Component, if I try to use them, I get the next error:

Property 'text' does not exist on type '{ children?: ReactNode; }'.

The code is like this: The props declaration:

    public props: IFirstButton = {
        text: "",
        entity: "",
        selectedField: "",
        context: null,
        onChangeText: this.onChangeText.bind(this)
    };

Here is the calling to the Component:

        ReactDom.render(
            React.createElement(AppComponentExample, this.props),
            this._container
        )

The Component calling Function Component:

    public render(): JSX.Element {
        return (
            <React.Fragment> 
            <PanelBasicExample {...this.props} ></PanelBasicExample>
            </React.Fragment>
        );
      }

And finally, the Function Component:

export const PanelBasicExample: React.FunctionComponent = (props) => {
  const [isOpen, { setTrue: openPanel, setFalse: dismissPanel }] = useBoolean(false);
  const searchText: any = "Selector Cuenta Bancaria" || props.text;
  console.log(props);
  const panelStyles: Partial<IPanelStyles> = {
    main: {
        alignContent: "center",
        '@media(min-width: 480px)': {
        width: "100%",
        position: "absolute",
        overflow: "hidden auto",
      }
    },
    header: {
      width: "100%",
      textAlign: "center"
    }
  }
  const panelStyle = {
    height: "80%",
    left: "25%",
    right: "25%"
  }
  return (
    <div>
      <DefaultButton text={searchText} onClick={openPanel} />
      <Panel
        headerText="Selector Cuenta Bancaria"
        isOpen={isOpen}
        onDismiss={dismissPanel}
        // You MUST provide this prop! Otherwise screen readers will just say "button" with no label.
        closeButtonAriaLabel="Cerrar"
        style={panelStyle}
        styles={panelStyles}
      >
        <TableExample {...props}></TableExample>
      </Panel>
    </div>
  );
};

PD: That console log logs what I'm expecting (the correct object with the data I need)

2
  • Where is the error? Commented Nov 24, 2020 at 12:38
  • Whenever I try to use a property from the props in the Function Component Commented Nov 24, 2020 at 12:46

1 Answer 1

1

the problem is most likely is the type declarations with the DefaultButton component(which you did not provide in the question code).

   <DefaultButton text={searchText} onClick={openPanel} />

add text:string to the props DefaultButton accepts.

Sign up to request clarification or add additional context in comments.

2 Comments

Hey! Thank you for your help! The Default Button is from the Fluent UI, that's why I didn't provide the code. Because of this, I can't change the props DefaultButton accepts.
Got it, try 'npm install @types/<theLibName>', sometimes when using typescript you need to the download the types defenitions in addition to the normal package

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.