react hooks for use with feathersjs
React hooks for use with feathersjs.
npm install --save feathers-react-hooks
useAuthentication
— tracks authentication status. calls app.authenticate()
useSetting
— tracks an application setting.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';
}
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>
);
}