Please tell me there is the following code:

import React, { Component } from 'react'; import styles from './table.css'; class App extends Component { constructor(props) { super(props); this.state = { VacTitle: '11' }; }; getApi(id){ fetch('https://api.hh.ru/vacancies/'+id) .then(function(response) { return response.json(); }) .then(function(data) { console.log('Request successful', data); return data; }) .catch(function(error) { console.log('Request failed', error) }); } render() { return ( <div> <img src="true" onError={this.getApi(this.props.id)} /> </div> ); } } export default App; 

How to display data received via getAPI in state? It does not work(

PS I did this (onError), since src is not, the function will work like window.onLoad :)

    1 answer 1

    Solved the issue

     import React, { Component } from 'react'; import ReactHtmlParser, { processNodes, convertNodeToElement, htmlparser2 } from 'react-html-parser'; import styles from './table.css'; class Vacan extends Component { constructor(props) { super(props); this.state = { VacTitle: '11', isLoad: false, data: [] }; }; componentDidMount(){ fetch(`https://api.hh.ru/vacancies/${this.props.id}`) .then(res => res.json()) .then(json => { this.setState({ isLoad: true, data: json, }) console.log(json); }) } render() { var { isLoad, data } = this.state; if (!isLoad) { return <div>Loading... < /div> } else { const html = '<h1>'+this.state.data.name+'</h1>' + this.state.data.description; return ( <div>{ ReactHtmlParser(html) }</div> ) } } } export default Vacan;