⊗jsrtPmIdRS 46 of 112 menu

Random strings for id in React

Now let the array of objects have the following form:

const prods = [ {id: 'GYi9G_uC4gBF1e2SixDvu', name: 'product1', cost: 100}, {id: 'IWSpfBPSV3SXgRF87uO74', name: 'product2', cost: 200}, {id: 'JAmjRlfQT8rLTm5tG2m1L', name: 'product3', cost: 300}, ];

As you can see, our id are now random unique strings. Such an array could have been obtained from a NoSQL database, or simply generated on the client.

Let's imagine again the situation with adding form data to this array. In this case, there will be no delay - when adding data, we will simply generate a random string, which will be the new id.

enru