Struggling to normalize deeply nested API response data? Look no further than https://github.com/paularmstrong/normalizr. This tool can help simplify your data structure.
For example, if your input data looks like this:
const data = [{
id: 'component1',
name: 'component one',
properties:[{
name: 'text',
color: 'red'
}]
},
{
id: 'component2',
name: 'component two',
properties:[{
name: 'text',
color: 'yellow'
},{
name: 'button',
color: 'blue'
}]
}]
The expected output after normalization should be:
{
entities: {
component1: {
id: 'component1',
name: 'component one',
properties: {
entities: {
text: {
name: 'text',
color: 'red'
}
},
results: ['text']
}
},
component2: {
id: 'component2',
name: 'component two',
properties: {
entities: {
text: {
name: 'text',
color: 'yellow'
},
button: {
name: 'button',
color: 'blue'
}
},
results: ['text', 'button']
}
}
},
results: ['component1', 'component2']
}
If you need any assistance, don't hesitate to ask for help.