0

how can I display toasts by traversing an array of objects, each of these objects with a unique id and names. I need to display a toast for each object inside this array, with a text and the value {item.name}.

Example: https://codesandbox.io/s/exciting-cloud-9oqhke?file=/src/App.js:0-583

In this example I used the React-toastify, and added the array of objects as an example, in that example there is a button that launches one toast with ALL names on it, but I need to press that button and it displays a toast for each object inside the array.

CodeAgainst
  • 143
  • 3
  • 12

1 Answers1

1

So you can call toast.error function for each array object like this

    const testData = [
      { id: 1, name: "John Doe" },
      { id: 2, name: "Victor Wayne" },
      { id: 3, name: "Jane Doe" }
    ];

    testData.map((user) => (
      toast.error(`${user.name} ${someText}`)
    ));
 
uz.
  • 51
  • 4