Home

Awesome

feathers-react CircleCI codecov

A Feathers real-time React component library to display data

Install

npm install --save feathers-react

Documentation

feathers-react consists of just a handful of React Components to help you display data coming from your Feathers API in real-time. Make sure to go through the channels docs to set up real-time events, otherwise the components won't update automagically.

Table props

<!-- | `prop` | Desc | No | `null` | -->
NameDescriptionRequiredDefault value
serviceThe Feathers service to get data from.Yesundefined
queryA Feathers query object to run against the specified service.No{}
keyPropThe result's property to use as key.No'id'
onRowClickClick event handler for a table row. The function takes two arguments: the row's data and its index.No(row, index) => {}
sortableA Boolean that determines wether a header can be clicked to sort resultsNoundefined
onDataChangeA callback Function that is invoked after the table's data changedNoundefined
countTemplateA string to use as template for showing items count. For example, 'Showing {start} to {end} of {total}' would render something like Showing 1 to 10 of 25.Noundefined
languageThe locale name to render translated text. Supported locales are ['fr_FR', 'en_US', 'es_ES'].No'en_US'
usePaginationDetermines wether to use the <Pagination /> component.Notrue
paginationPropsAn Object to override rc-pagination's props.Noundefined

Column props

<!-- | `prop` | Desc | No | `null` | -->
NameDescriptionRequiredDefault value
dataSourceThe result's property to extract data from.Only when render is not definedundefined
renderA render function that takes two arguments: the data for the column and the row's data. For example, imageUrl => <img src={imageUrl} /> would render an image in the table cell.Noundefined
titleA string to use as the header for the column.Noundefined
widthThe column's visual width, in pixels.Noundefined

Example

In this simple example, the <Table /> component takes a client prop which is a Feathers client.

import React from 'react';
import { Column, Table } from 'feathers-react';
import 'feathers-react/style.css';

export default ({ client }) => {
  const service = client.service('some-service');
  const query = { $sort: { name: 1 } };

  return (
    <Table service={service} query={query}>
      <Column
        title="Image"
        dataSource="imageUrl"
        render={(data, row) => (
          <img alt={row.name} src={data} />
        )} />
      <Column
        title="Name"
        dataSource="name" />
    </Table>
  );
};

Container props

The <Container /> component is a generic wrapper that you can use to present data in a different format than tabular. It shares most props with the <Table /> component, the main difference is that it doesn't take any children, but has a renderItem prop to render data.

NameDescriptionRequiredDefault value
serviceThe Feathers service to get data from.Yesundefined
queryA Feathers query object to run against the specified service.No{}
emptyStateAn HTMLElement, React component, or String to render when there are no results.Noundefined
keyPropThe result's property to use as key.No'id'
renderItemA render function that can return a React component. The function takes two arguments: the row's data and its index.Yes(row, index) => <SomeComponent key={row.id} data={row} />
itemsWrapperAn HTMLElement or React component that will wrap rendered children.Noundefined
separatorA render function to use as a separator. It takes one argument: the current result being iterated. It requires both: itemsWrapper and query.$sort to be defined.Noundefined
countTemplateA string to use as template for showing items count. For example, 'Showing {start} to {end} of {total}' would render something like Showing 1 to 10 of 25.Noundefined
languageThe locale name to render translated text. Supported locales are ['fr_FR', 'en_US', 'es_ES'].No'en_US'
usePaginationDetermines wether to use the <Pagination /> component.Nofalse
hidePaginationOnSinglePageHides the pagination component when there's only one page of dataNoundefined
paginationPropsAn Object to override rc-pagination's props.Noundefined

Example

import React from 'react';
import { Container } from 'feathers-react';
import 'feathers-react/style.css';
import Message from './message';

export default ({ client }) => {
  const service = client.service('messages');
  const query = { $sort: { author: 1 } };

  return (
    <Container
      service={service}
      query={query}
      itemsWrapper={<div className="messages-wrapper" />}
      separator={message => <h3>Messages by {message.author}</h3>}
      renderItem={message => (
        <Message key={message.id} message={message} />
      )} />
  );
};

License

MIT © Silvestre Herrera