Skip to content

💫 React bindings for Orbit.js. Inspired by react-redux.

License

Notifications You must be signed in to change notification settings

exivity/react-orbitjs

Repository files navigation

react-orbitjs

npm ci Codecov Code Climate

React bindings for Orbit.

This package attempts to make it easier to work with Orbit.js in a React environment. In a nutshell it's a transform listener, updating a component props with records as they are changed. If you're familiar with redux in combination with react-redux, you already know how to use this package.



A big thank you to the author and contributers of the popular react-redux package, as react-orbitjs is largely based on their code.

Installation

react-orbitjs requires Orbit 0.16.x or 0.17.x.

npm

npm install --save react-orbitjs

yarn

yarn add react-orbitjs

API

<DataProvider/>

const store = new MemorySource({schema})

// Simply pass a reference to your Orbit store to the <DataProvider/> component
// and wrap your root App component. The provider makes a dataStore child
// context available to all children, which is consumed by the HOC generated
// with the withData() connector.
ReactDOM.render(
  <DataProvider dataStore={store}>
    <App/>
  </DataProvider>,
  rootElement
)

withData()

// This mapper uses the props passed in to manipulate the queries. Useful for
// sort/filter functions, etc.
const mapRecordsToProps = (ownProps) => {
  return {
    planets: q => q.findRecords("planet").sort(ownProps.sortBy),
  }
}

// Or use a simple object if you don't use the props in your queries.
const mapRecordsToProps = {
  planets: q => q.findRecords("planet"),
}

// Export the generated component. Your <Planetarium/> component receives all
// the props you pass to the wrapper component, combined with the results from
// the queries defined in the mapRecordsToProps function or object, and
// convenience queryStore and updateStore props, which defer to store.query and
// store.update.
export default PlanetariumWithData = withData(mapRecordsToProps)(Planetarium)

License

MIT