D
D
Daniel Chistyakov2021-05-10 11:57:42
JavaScript
Daniel Chistyakov, 2021-05-10 11:57:42

How to change styles on a specific React child element?

How to change the styles of a specific child element that was clicked on on click?
Here is my code:

<div>
{arr.map((res, key) => (
<span key={key} onClick('что здесь писать?') className={'elem'}>{res + 1} элемент</span>
))}
</div>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Laud, 2018-10-30
@IT-Programmer

If the logic for receiving data is very similar, and only, for example, addresses for the API change, then you can do everything in one place. If the differences are large enough, then it is better to split it so that it is easier to maintain later.

E
eugene none, 2021-05-10
@danielchistyakov

handleClick=(e)=>{
e.preventDefault();
e.target.style.color = 'black'
console.log(e.target);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question