I'm using normalizr
util to process API response based on non-ids model. As I know, typically normalizr
works with ids model, but maybe there is a some way to generate ids "on the go"?
My API response example:
```
// input data:
const inputData = {
doctors: [
{
name: Jon,
post: chief
},
{
name: Marta,
post: nurse
},
//....
}
// expected output data:
const outputData = {
entities: {
nameCards : {
uniqueID_0: { id: uniqueID_0, name: Jon, post: uniqueID_3 },
uniqueID_1: { id: uniqueID_1, name: Marta, post: uniqueID_4 }
},
positions: {
uniqueID_3: { id: uniqueID_3, post: chief },
uniqueID_4: { id: uniqueID_4, post: nurse }
}
},
result: uniqueID_0
}
```
P.S.
I heard from someone about generating IDs "by the hood" in normalizr
for such cases as my, but I did found such solution.
As mentioned in this issue:
And then, as mentioned in the docs, you need to set
idAttribute
to replace 'id' with another key:EDIT
You can always provide unique id's using external lib or by hand:
Have a processStrategy which is basically a function and in that function assign your id's there, ie.
value.id = uuid()
. Visit the link below to see an example https://github.com/paularmstrong/normalizr/issues/256