This package has been deprecated

Author message:

WARNING: This project has been renamed to react-native-realm. Install using react-native-realm instead.

realm-react

0.1.0 • Public • Published

realm-react

A higher-order component for listening to Realm data in React components.

Usage

// the file you use to wire up your realm schemas, etc.
import realm from './path/to/your/realm/file';
 
...
// render function of your top level component for your app
render() {
  <RealmProvider realm={realm}>
    <MyComponent />
  </RealmProvider>
}
...
import { connectRealm } from 'realm-react';
 
class MyComponent extends Component {
 
  addPerson = () => {
    const { realm } = this.props;
    realm.write(() => {
      realm.create('Person', {
        firstName: 'Tim',
      });
    });
  };
 
  render() {
    <PeopleList people={this.props.people} />
  }
}
 
export default connectRealm(MyComponent, {
  schemas: ['Person'],
  mapToProps(results, realm) {
    // the object that is returned from the mapToProps function
    // will be merged into the components props
    return {
      realm,
      // property on the results argument is the camel-cased and
      // pluralized version of the schema name, so...
      // instead of person being the property we get people
      people: results.people,
    };
  },
});

Examples

Check out the example react native app to see realm-react in use.

Readme

Keywords

Package Sidebar

Install

npm i realm-react

Weekly Downloads

20

Version

0.1.0

License

MIT

Last publish

Collaborators

  • jasonmerino