Allows easy use of Hooks written with Ironhook in React.
Using yarn
:
yarn add ironhook-react
Using npm
:
npm install ironhook-react --save
The following is a constructed example that demonstrates the use of this library:
import * as Ironhook from 'ironhook';
import * as IronhookReact from 'ironhook-react';
import * as React from 'react';
function useName() {
const [name, setName] = Ironhook.useState('World');
Ironhook.useEffect(() => {
setTimeout(() => setName('John Doe'), 10);
}, []);
return name;
}
function Hello() {
const nameSubject = React.useMemo(() => new Ironhook.Subject(useName), []);
const nameResult = IronhookReact.useIronhook(nameSubject);
switch (nameResult.type) {
case 'value':
return <h1>Hello, {nameResult.value}!</h1>;
case 'error':
return <h1>Oops!</h1>;
case 'completed':
return <h1>Bye.</h1>;
}
}
<Hello />
function useIronhook<TValue>(
subject: Ironhook.Subject<TValue>
): IronhookResult<TValue>;
type IronhookResult<TValue> =
| {readonly type: 'value'; readonly value: TValue}
| {readonly type: 'error'; readonly error: Error}
| {readonly type: 'completed'};
yarn release patch
yarn release minor
yarn release major
After a new release has been created by pushing the tag, it must be published via the GitHub UI. This triggers the final publication to npm.
Copyright (c) 2020, Clemens Akens. Released under the terms of the MIT License.