N
N
nikmil2019-12-03 01:20:41
React
nikmil, 2019-12-03 01:20:41

Why does React update the state of the images at the same time if it is the same for everyone?

Good evening, tell me please, I have 2 gif pictures - start and stop.
I import them ->

import start from '../../img/start.gif';
import stop from '../../img/stop .gif';

In my smell it is indicated ->
array: [
                {name: 'user1',  animation: false},
                {name: 'user2',  animation: true}
            ],

I have this picture in the map and so that they replace each other I use ->
{this.state.array.map((e, index) => {
i = 'animation' + index
return (
<div key={i} .....
     <img src={e.animation ?  start : stop}  width="20" height="20"/>
</div>
)
})}

Pictures change when boolean changes, but if it is true and true (or false and false), then both pictures are reloaded at the same time, how to avoid this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ice, 2019-12-03
@IceRD

let products = [...this.state.animation];
//ваш код
this.setState({products});

Don't change state directly

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question