0

Here is the piece of my index.ts code (where I call the component to display)

        <GlobalContext.Provider value={this.globalContext as IGlobalContext}>
            <Container maxWidth="lg">
                <Switch>
                    <Route path="" component={HelloWorld} elements={this.getResults()}/>
                </Switch>
            </Container>
        </GlobalContext.Provider>

Here is the piece of the helloWorld.ts file (the beggining)

import React from 'react';

export default class HelloWorld extends React.Component {

    public render(): JSX.Element {
        let elements = this.props.elements; // I Want to get the elements props passed throuth my router component
        ....

Why can't I get the this.props.elements in the helloWorld.ts file ? How can I do it ?

I Have the error : Property 'elements' does not exist on type 'Readonly<{}> & Readonly<{ children?: ReactNode; }>'. TS2339

Sarun UK
  • 6,210
  • 7
  • 23
  • 48
  • Without the error message you're getting, it's hard to determine your problem. You also want to create a minimal working example to show what you're doing. – Kielstra Dec 21 '20 at 14:59
  • Yes, I edited my post. – DispénNém Dec 21 '20 at 15:01
  • Does this answer your question? [Property 'XYZ' does not exist on type 'Readonly<{ children?: ReactNode; }> & Readonly<{}>'](https://stackoverflow.com/questions/52249390/property-xyz-does-not-exist-on-type-readonly-children-reactnode-rea) – Kielstra Dec 21 '20 at 15:05
  • Does `elements` exist on the Route element? – Matt K Dec 21 '20 at 15:07
  • @DispénNém did the answer solve your problem ? – Sats Dec 22 '20 at 11:51

1 Answers1

0

Use constructor and also lose the 'this' in render method.

   constructor(props)
{
    super(props);
}

public render(): JSX.Element {
 let elements = props.elements;
            ....

Just use props.elements instead of this.props.elements

Sats
  • 1,913
  • 1
  • 15
  • 21