Related Resources
normalizr
import { normalize, schema } from 'normalizr';
import store from './store';
const user = new schema.Entity('users');
const comment = new schema.Entity('comments', {
commenter: user
});
const article = new schema.Entity('articles', {
author: user,
comments: [comment]
});
const originalData = [{
id: '123',
author: {
id: '1',
name: 'Paul'
},
title: 'My awesome blog post',
comments: [
{
id: '324',
commenter: {
id: '2',
name: 'Nicole'
}
}
]
}];
const normalizedData = normalize(originalData, [article]);
const action = {
type: actionTypes.READ_RESOURCES_SUCCEEDED,
// We recommend that you use the same string for the `resourceType`, resource slice,
// and normalizr key.
resourceType: article.key,
resources: normalizedData.result,
includedResources: normalizedData.entities
};
store.dispatch(action);JSON API
GraphQL
Last updated