Each store creates a set of default selectors for your convenience.
Just returns all objects in the collection.
const userStore = createEntityStore('users')
function mapStateToProps(state) {
return {
users: userStore.getAll(state)
}
}
Returns and memoizes single entity object.
const userStore = createEntityStore('users')
function mapStateToProps(state) {
return {
user: userStore.getObject(state, 1)
}
}
Returns and memoizes single entity object.
const userStore = createEntityStore('users')
const getSelectedUser = userStore.createFindSelector(function (state) {
return state.selectedUserId
})
function mapStateToProps(state) {
return {
user: getSelectedUser(state)
}
}
Given following state, it would return object representing Commander Data.
{
"entities": {
"users": [
{
"id": 1,
"name": "LCDR Data"
}
]
},
"selectedUserId": 1
}
Returns and memoizes single object property
const userStore = createEntityStore('users')
function mapStateToProps(state) {
return {
userName: userStore.getProp(state, 1, 'name')
}
}
Returns and memoizes single object property, assuming it is a boolean
const userStore = createEntityStore('users')
function mapStateToProps(state) {
return {
hasName: userStore.getFlag(state, 1, 'name')
// returns true or false
}
}