Answer the question
In order to leave comments, you need to log in
How to render array elements one by one on a button in React?
Good day. It became interesting whether it is possible to render elements of an array one by one in React, for example, on the onClick of a button, and how to implement it. Here is a sample code
const array = [
{
field: 'first field',
id: 1
},
{
field: 'second field',
id: 2
},
{
field: 'third field',
id: 3
},
{
field: 'fourth field',
id: 4
}
];
const SomeComponent = () => (
<>
{array.map(el => (
<span key={el.id}>{el.field}</span>
))}
<button onClick={handleField}>Next field</button>
</>
);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question