Skip to content

Commit c1d44bd

Browse files
committed
docs: add ShouldUpdate docs
1 parent c54d8b7 commit c1d44bd

File tree

3 files changed

+50
-9
lines changed

3 files changed

+50
-9
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ const MyComponent = mock();
3636
- [`mock()`](./docs/en/mock.md) and [`loadable()`](./docs/en/loadable.md)
3737
- [`lazy()`](./docs/en/lazy.md), [`delayed()`](./docs/en/delayed.md), and [`viewport()`](./docs/en/viewport.md)
3838
- [Inversion](./docs/en/Inversion.md)
39-
- [`invert()`](./docs/en/invert.md) and [`<Inverted>`](./docs/en/invert.md#inverted)
40-
- `<ShouldUpdate>`
4139
- [`<State>`](./docs/en/State.md) and [`withState()`](./docs/en/State.md#withstate-hoc)
4240
- [`<Toggle>`](./docs/en/Toggle.md), [`withToggle()`](./docs/en/Toggle.md#withtoggle-hoc), and [`@withToggle`](./docs/en/Toggle.md#withtoggle-decorator)
4341
- [`<Flipflop>`](./docs/en/Flipflop.md), [`withFlipflop()`](./docs/en/Flipflop.md#withflipflop-hoc), and [`@withFlipflop`](./docs/en/Flipflop.md#withflipflop-decorator)
4442
- [`<Value>`](./docs/en/Value.md), [`withValue()`](./docs/en/Value.md#withvalue-hoc), and [`@withValue`](./docs/en/Value.md#withvalue-decorator)
4543
- [`<Counter>`](./docs/en/Counter.md), [`withCounter()`](./docs/en/Counter.md#withcounter-hoc) and [`@withCounter`](./docs/en/Counter.md#withcounter-decorator)
4644
- [`<List>`](./docs/en/List.md), [`withList()`](./docs/en/List.md#withlist-hoc), and [`@withList`](./docs/en/List.md#withlist-decorator)
4745
- [`<Map>`](./docs/en/Map.md), [`withMap()`](./docs/en/Map.md#withmap-hoc), and [`@withMap`](./docs/en/Map.md#withmap-decorator)
46+
- [`<ShouldUpdate>`](./docs/en/ShouldUpdate.md), [`shouldUpdate()`](./docs/en/ShouldUpdate.md#shouldupdate-hoc), and [`pure()`](./docs/en/pure.md)
47+
- [`invert()`](./docs/en/invert.md) and [`<Inverted>`](./docs/en/invert.md#inverted)
4848
- [Sensors](./docs/en/Sensors.md)
4949
- [`<ActiveSensor>`](./docs/en/ActiveSensor.md), [`withActive()`](./docs/en/ActiveSensor.md#withactive-hoc), and [`@withActive`](./docs/en/ActiveSensor.md#withactive-decorator)
5050
- [`<BatterySensor>`](./docs/en/BatterySensor.md), [`withBattery()`](./docs/en/BatterySensor.md#withbattery), and [`@withBattery`](./docs/en/BatterySensor.md#withbattery-1)

docs/en/README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
- [`mock()`](./mock.md) and [`loadable()`](./loadable.md)
66
- [`lazy()`](./lazy.md), [`delayed()`](./delayed.md), and [`viewport()`](./viewport.md)
77
- [Inversion](./Inversion.md)
8+
- [`<State>`](./State.md) and [`withState()`](./State.md#withstate-hoc)
9+
- [`<Toggle>`](./Toggle.md), [`withToggle()`](./Toggle.md#withtoggle-hoc), and [`@withToggle`](./Toggle.md#withtoggle-decorator)
10+
- [`<Flipflop>`](./Flipflop.md), [`withFlipflop()`](./Flipflop.md#withflipflop-hoc), and [`@withFlipflop`](./Flipflop.md#withflipflop-decorator)
11+
- [`<Value>`](./Value.md), [`withValue()`](./Value.md#withvalue-hoc), and [`@withValue`](./Value.md#withvalue-decorator)
12+
- [`<Counter>`](./Counter.md), [`withCounter()`](./Counter.md#withcounter-hoc) and [`@withCounter`](./Counter.md#withcounter-decorator)
13+
- [`<List>`](./List.md), [`withList()`](./List.md#withlist-hoc), and [`@withList`](./List.md#withlist-decorator)
14+
- [`<Map>`](./Map.md), [`withMap()`](./Map.md#withmap-hoc), and [`@withMap`](./Map.md#withmap-decorator)
15+
- [`<ShouldUpdate>`](./ShouldUpdate.md), [`shouldUpdate()`](./ShouldUpdate.md#shouldupdate-hoc), and [`pure()`](./pure.md)
816
- [`invert()`](./invert.md) and [`<Inverted>`](./invert.md#inverted)
9-
- [`<State>`](./State.md) and [`withState()`](./State.md#withstate-hoc)
10-
- [`<Toggle>`](./Toggle.md), [`withToggle()`](./Toggle.md#withtoggle-hoc), and [`@withToggle`](./Toggle.md#withtoggle-decorator)
11-
- [`<Flipflop>`](./Flipflop.md), [`withFlipflop()`](./Flipflop.md#withflipflop-hoc), and [`@withFlipflop`](./Flipflop.md#withflipflop-decorator)
12-
- [`<Value>`](./Value.md), [`withValue()`](./Value.md#withvalue-hoc), and [`@withValue`](./Value.md#withvalue-decorator)
13-
- [`<Counter>`](./Counter.md), [`withCounter()`](./Counter.md#withcounter-hoc) and [`@withCounter`](./Counter.md#withcounter-decorator)
14-
- [`<List>`](./List.md), [`withList()`](./List.md#withlist-hoc), and [`@withList`](./List.md#withlist-decorator)
15-
- [`<Map>`](./Map.md), [`withMap()`](./Map.md#withmap-hoc), and [`@withMap`](./Map.md#withmap-decorator)
1617
- [Sensors](./Sensors.md)
1718
- [`<ActiveSensor>`](./ActiveSensor.md), [`withActive()`](./ActiveSensor.md#withactive-hoc), and [`@withActive`](./ActiveSensor.md#withactive-decorator)
1819
- [`<BatterySensor>`](./BatterySensor.md), [`withBattery()`](./BatterySensor.md#withbattery), and [`@withBattery`](./BatterySensor.md#withbattery-1)

docs/en/ShouldUpdate.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# `<ShouldUpdate>`
2+
3+
Inverts `.shouldComponentUpdate()` life-cycle method. Allows you to use specify whether its children should update based
4+
on passed in props.
5+
6+
7+
## Usage
8+
9+
The below example will always re-render on new `data`, because `when` method always returns `true`.
10+
11+
```jsx
12+
import {ShouldUpdate} from 'libreact/lib/ShouldUpdate';
13+
14+
<ShouldUpdate when={(newProps, oldProps) => true} props={data}>{(props) =>
15+
<div>Hello world!</div>
16+
}</ShouldUpdate>
17+
```
18+
19+
20+
## Props
21+
22+
- `when` &mdash; required, function, return boolean whether its children should re-render. Receives new and old props as two arguments.
23+
- `props` &mdash; required, object, props to pass to children.
24+
25+
26+
## `shouldUpdate()` HOC
27+
28+
Higher order component that re-renders only when a condition is met.
29+
30+
```jsx
31+
import {shouldUpdate} from 'libreact/lib/ShouldUpdate';
32+
33+
const PrintOver3 = shouldUpdate((props) => props.cnt > 3)(Print);
34+
```
35+
36+
The above example creates a `PrintOver3` component that will re-render only when
37+
`cnt` prop is greater than 3.
38+
39+
40+
See also [`pure()`](./pure.md).

0 commit comments

Comments
 (0)