Answer the question
In order to leave comments, you need to log in
How to add logic for an attribute in React?
Good day!
There is a map loop that iterates over the array and creates inputs from it, and it is necessary that when creating only the first input have the checked attribute:
{dots.map((item, index) => <input checked type='radio' name="dot" key={index} className={s.Dot} />)}
Answer the question
In order to leave comments, you need to log in
You have an index, you need to make the input with index 0 checked={true}. With a simple movement of the hand, we check whether the current index is equal to 0, and assign the resulting value to the checked property of the input.
...
<input checked={index === 0} {...props} />
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question