D
D
Dmitry Nikolaev2020-02-02 10:57:19
React
Dmitry Nikolaev, 2020-02-02 10:57:19

Why is the variable not inserted in JSX?

An image should be inserted into the src tag, but unknown is inserted5e368113e5bfa344563028.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
LinkVP, 2020-02-02
@kaleniybrat

Inside the component:

this.state = {
beerImage: null,
}

componentDidMount() {
promise.then(beer => this.setState({beerImage: beer.image}))
}

Further inside render(): and now beerImage can be passed to src (if beerImage returns the path to the image):
const {beerImage} = this.state;
<img src={beerImage} />

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question