treble-hook
Advanced tools
Comparing version 1.0.4 to 1.0.5
{ | ||
"name": "treble-hook", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Get hooked on simple subscribe-and-publish in ReactJS.", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -12,12 +12,56 @@ <div align="center"> | ||
### yarn | ||
```sh | ||
yarn add @igneous.io.ux/treble-hook | ||
yarn add treble-hook | ||
``` | ||
### npm | ||
### or | ||
```sh | ||
npm install --save @igneous.io.ux/treble-hook | ||
npm install --save treble-hook | ||
``` | ||
## Usage | ||
Contrived sign-in component and a component that displays active user (signed-in user). | ||
```tsx | ||
import React, { ChangeEvent, useState } from 'react' | ||
import usePubSub from 'treble-hook' | ||
const ACTIVE_USER_TOPIC = 'active-user' | ||
function SignIn() { | ||
const [_, publishUser] = usePubSub<string>(ACTIVE_USER_TOPIC, '') | ||
const [entered, setEntered] = useState<string>('') | ||
return ( | ||
<div> | ||
<input | ||
type='text' | ||
onChange={ | ||
(evt: ChangeEvent<HTMLInputElement>) => { | ||
setEntered(evt.target.value) | ||
} | ||
} | ||
/> | ||
<button onClick={ () => { publishUser(entered) }}>Sign-in</button> | ||
</div> | ||
) | ||
} | ||
function ActiveUser() { | ||
const [activeUser] = usePubSub<string>( | ||
ACTIVE_USER_TOPIC, | ||
'Anonymous' | ||
) | ||
return <h3>Active user: { activeUser }</h3> | ||
} | ||
``` | ||
## TLDR; (jump right into it) | ||
@@ -27,6 +71,6 @@ | ||
```TSX | ||
```tsx | ||
import usePubSub from '@igneous.io.ux/treble-hook' | ||
import React, { FC } from 'react' | ||
import React from 'react' | ||
import usePubSub from 'treble-hook' | ||
import { BluePicker, GreenPicker, RedPicker } from './color-buttons' | ||
@@ -65,6 +109,6 @@ | ||
```JSX | ||
```tsx | ||
import usePubSub from '@igneous.io.ux/treble-hook' | ||
import React from 'react' | ||
import usePubSub from 'treble-hook' | ||
@@ -71,0 +115,0 @@ const ColorButton = <{ cn: string }>({ cn }) => { |
14245
185