Let's suppose an API call is made at the backend, a value is being fetched from the API, and this value needs to be shown inside the input tag (jsx). How to show that value?
2 Answers
You just need to set it your component's state using the setState function. A possible scenario might be:
componentDidMount() {
fetchSomeData().then((data) => {
this.setState({value: data})
});
}
/* ... later, in your render function */
<input value={this.state.value} />
For more information on how setState works (and to learn more about the entire React lifecycle), see https://reactjs.org/docs/react-component.html#setstate