feathers-react-hooks

react hooks for use with feathersjs

View the Project on GitHub

current version Build Status Coverage Status Mutation testing badge semantic-release Commitizen friendly

React hooks for use with feathersjs.

Install

npm install --save feathers-react-hooks

Hooks

useAuthentication

Tracks authentication status. Calls app.authenticate().

import { useAuthentication } from 'feathers-react-hooks';

export default function YourReactComponent() {
  const isAuthenticated = useAuthentication(app);

  if (isAuthenticated === null) {
    return 'authenticating...';
  }

  return isAuthenticated
    ? 'authenticated!'
    : 'not authenticated';
}

useSetting

Tracks an application setting.

import { useSetting } from 'feathers-react-hooks';

export default function YourReactComponent() {
  const [value, setValue] = useSetting(app, 'setting_name', 'default value');

  return (
    <button type="button" onClick={() => setValue('new value')}>
      {value}
    </button>
  );
}