Skip to content

Records

Michael Niday edited this page Jun 6, 2018 · 1 revision

Basic record setup

Creating records take a shape like the following, where each item in this object will be available to the collection provided by the entities HOC

people: {
  id: null,
  url: null,
  name: null,
  homeworld: null
}

NOTE: even though more attributes are returned via the API, only those listed here will be available to this.props.collection.item[attribute]

Example

By using the entities HOC, we define a prop for Component called person this.props.person.item is the item fetched from the database (if a single ID is fetched) OR the first item in a list of this.props.person.items

import { entities } from 'entities'

class Component extends React.Component {
  renderPerson = () => {
    const { person: { item } } = this.props
    return (
      <div>
        <p>Name: {item.name}</p>
      </div>
    )
  }

  render () {
    return this.renderPerson()
  }
}

export default entities({person: {type: 'people'}})(Component)

As more attributes are added to your API, they essentially need to be whitelisted in your records config

Clone this wiki locally