0

I'm following along a React tutorial, And I come across this syntax:

const itemsFromBackend = [
  { id: uuid(), content: "First task" },
  { id: uuid(), content: "Second task" },
  { id: uuid(), content: "Third task" },
  { id: uuid(), content: "Fourth task" },
  { id: uuid(), content: "Fifth task" }
];

const columnsFromBackend = {
 
  [uuid()]: {
    name: "Todo",
    items: itemsFromBackend
  }

};

What does it means this [uuid()]:{ } array-Object syntax in relation with the first array of tasks itemsFromBackend? I saw something similar while handling changes in React forms, but not sure if it's the same thing. Thanks for the help!

  • 2
    That is a function to generate a unique id. Check for instance https://www.npmjs.com/package/nanoid. A link to the React docs could be helpful just to have more context. – Artur Carvalho Apr 09 '21 at 16:30
  • 1
    It's a dynamically evaluated key name. The object will have a UUID for a key. – VLAZ Apr 09 '21 at 16:31
  • 2
    That's *computed property name* syntax, which sets the name of the property on the object by evaluating an expression. The expression in your case is `uuid()`, a call to the `uuid` function. Whatever that function returns is what is used as the name of the property. – T.J. Crowder Apr 09 '21 at 16:31

0 Answers0