0.2.0 • Published 4 years ago
ironhook-react v0.2.0
ironhook-react
Allows easy use of Hooks written with Ironhook in React.
Installation
Using yarn
:
yarn add ironhook-react
Using npm
:
npm install ironhook-react --save
Usage Example
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 />
API Reference
Types
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'};
Development
Publish A New Release
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.