Skip to content

Latest commit

 

History

History
87 lines (58 loc) · 1.67 KB

README.md

File metadata and controls

87 lines (58 loc) · 1.67 KB

React higher order components for the deepstream.io server.

Usage

withRecord

Provides the deepstream record to the component.

Properties passed to the wrapped component:

  • record an object containing the record's properties
  • onChange a callback that can be called when the record has changed
import React from 'react';
import { withRecord } from 'deepstream.io-react-hoc';

const Component = (props) => (
    <div>
        {JSON.serialize(props.record)}
    </div>
    );

const ConnectedComponent = withRecord(Component, 'record-name');

//use it:
(
    <ConnectedComponent ds={dsClient} />
)

withList

Provides the deepstream list entries to the component.

Properties passed to the wrapped component:

  • entries an array with the entries held by that list
  • addEntry a callback that can be called to add an entry to the list
import React from 'react';
import { withList } from 'deepstream.io-react-hoc';

const Component = (props) => (
    <div>
        {props.entries.map(entry => (<div>{entry}</div>)}
    </div>
    );

const ConnectedComponent = withList(Component, 'list-name');

//use it:
(
    <ConnectedComponent ds={dsClient} />
)

withRPC

Calls the deepstream RPC method.

Properties passed to the wrapped component:

  • rpcResult the result returned by the deepstream server
import React from 'react';
import { withRPC } from 'deepstream.io-react-hoc';

const Component = (props) => (
    <div>
        {JSON.stringify(props.rpcResult)}
    </div>
    );

const ConnectedComponent = withRPC(Component, 'rpcName', rpcOptionalArgs);

//use it:
(
    <ConnectedComponent ds={dsClient} />
)