Skip to content

Commit

Permalink
fixup! docs(readme): add usage section
Browse files Browse the repository at this point in the history
  • Loading branch information
smmoosavi committed Jan 9, 2022
1 parent e9d0e25 commit 5fa071e
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,17 @@ function FancyList(props) {
const [filter, setFilter] = useState('');
return (
<>
<FnacyInput value={filter} setValue={setFilter} />
<FancyInput value={filter} setValue={setFilter} />
<List items={props.items} filter={filter} />
</>
);
}
```

- you need to refactor all `FancyInput` usage, pass `value`, and `setValue` to make it work as expected
- the top-level component (`FancyList`) re-render each time the `filter` changes
- you need to refactor all the `FancyInput` usages, pass `value`, and `setValue` to make it work as expected
- the top-level component (`FancyList`) re-renders each time the `filter` changes

Let see how react-wire help you:
Let see how react-wire helps you:

```tsx
function FancyInput(props) {
Expand All @@ -105,7 +105,7 @@ function FancyInput(props) {
}
```

Same as above, but use `useWireState` instead of `useState`, right now `FancyInput` is uncontrolled. Now, if you need to make it controllable, you should pass an up-link wire.
Same as above, but use `useWireState` instead of `useState`, right now `FancyInput` is uncontrolled. If you need to make it controllable, you should pass an up-link wire.

```diff
function FancyInput(props) {
Expand All @@ -123,7 +123,7 @@ function FancyList(props) {
const filter$ = useWire(null, '');
return (
<>
<FnacyInput value$={filter$} />
<FancyInput value$={filter$} />
<List items={props.items} filter$={filter$} />
</>
);
Expand All @@ -132,10 +132,10 @@ function FancyList(props) {

With this new code:

- all `FancyInput` uncontrolled usage is working as expected without any change
- all the `FancyInput` uncontrolled usages are working as expected without any change
- the Top-level component (`FancyList`) will not re-render each time the value changes
- only detailed components (`FancyInput`, `List`) will re-render each time the value changes
- `FancyInput` is now controllable and can be used as a controlled or uncontrolled component by passing a wire.
- `FancyInput` is now controllable and can be used as a controlled or uncontrolled component by passing a wire
- `FancyList` can be controllable if you want:

```tsx
Expand All @@ -145,7 +145,7 @@ function FancyList(props) {
}
```

react-wire have more advanced features:
react-wire has more advanced features:

- selectors to maintain calculated values
- fns to pass function calls over the wire
Expand Down

0 comments on commit 5fa071e

Please sign in to comment.