I\'m getting a ts error from my react component. The component is running fine, building etc, however typescript is showing an error inside the ide. Not sure how i need to d
Here's an example of how to use the state and render the components:
type HomeProps = {
text: string;
}
class Home extends React.Component {
public render() {
return { this.props.text }
}
}
type AppState = {
homeText: string;
}
class App extends React.Component {
constructor() {
super();
this.state = {
homeText: "home"
};
setTimeout(() => {
this.setState({ homeText: "home after change "});
}, 1000);
}
render() {
return
}
}
As you can see, the props and state objects are always simple, and the rendering method is in charge of creating the actual components.
This way react knows which components are changed and which parts of the DOM tree should be updated.