I am trying to type the props of my component and use an URL param at the same time. I get the following error:
Property 'match' does not exist on type 'Readonly<{children?:ReactNode}> & Readonly'
Here is some of my code:
import Api from '../../api/Api';
interface MyProps {
api: Api
}
interface MyState {
someString: string,
loading: boolean
}
export class MyComponent extends React.Component<MyProps, MyState> {
constructor(props: MyProps) {
super(props);
this.state = {
someString: this.props.match.params.someString,//<-- Error is here on this line
loading: true
}
}
componentDidMount() {
this.props.api.getSomeInfo(this.state.someString, this.callback)
}
callback() {
let interval = setInterval(function () {
this.setState({loading: false});
clearInterval(interval)
}, 3000);
}
render() {
return (
<div>
<p>{this.someString}</p>
</div>
);
}
}
As you can see all I am trying to do is:
1- Go to:
2- Grab the value of :someString in my component's constructor and store in state
3- Use the value of someString in my state to be able to pass it as an argument to my API module to do stuff
4- When the callback is executed in the API I remove the loading animation
My question is basically, how do I declare my MyProps to be able to acheive this?