score:1

Accepted answer

you have two options here:

  1. the suggested way is to generate a unique key when adding a new todo like this:
const todo = {
  id: new date().gettime(), //a better way might be to use a uuid library to generate this
  title: title,
  finished: false,
};
  1. is to use index + title as key just to make react happy, like this:
const mappedtodolist = todolist?.map((element, index) => {
    return (
        <div classname='to-do' key={element.title + index}>
            <p>{element.title}</p>
        </div>
    )
})

score:-1

you can map over the list like this:

const numbers = [1, 2, 3, 4, 5];

const listitems = numbers.map((number) =>
  <li>{number}</li>
 );

score:0

you can use uuid library

npm install uuid

then you can add a unique id for your item

  
import { v4 as uuidv4 } from 'uuid';
 const todo = {
        id: uuidv4(),
        title: title,
        finished: false,
    }


Related Query

More Query from same tag