ReactJs — Lists and Keys
You can render lists in React by using the map()
function. Each item should have a unique key to help React identify which items have changed, been added, or removed.
function TodoList() {
const todos = ['Learn React', 'Build a Project', 'Get a Job'];
return (
<ul>
{todos.map((todo, index) => (
<li key={index}>{todo}</li>
))}
</ul>
);
}
export default TodoList;