You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
:electric_plug: Give life to your Dumb Components.
10
10
11
-
**React PowerPlug is a *Just add water™*** set of **function as children components** that add different types of state logics in your dumb components. It creates a state and pass down the logic to the children, so you can handle your data/callbacks in dumb components.
11
+
---
12
+
> I'm working on version 1.0. [Follow me on twitter](http://twitter.com/renatorib_) to know when news will come up.
13
+
---
12
14
13
-
It's has been created to (but not limited to) use with **storybook, react styleguidist, documentations, etc**. because it's the most common use case. Otherwise you can use in your normal components too, for example a Dropdown that needs to know if opened or not, and others cases.
15
+
**React PowerPlug is a *Just add water™*** set of **render props (or function as children) components** that provides different types of state and logics so you can use with your dumb components. It creates a state and pass down the logic to the children, so you can handle your data/callbacks.
16
+
17
+
It's has been created to (but not limited to) use with **storybook, react styleguidist, documentations, prototypes**. You can also use to create a bunch of uncontrolled components where the outside app don't care about your state, for example a menu dropdown.
14
18
15
-
[Play with live Toggle example on CodeSandbox](https://codesandbox.io/s/jp890p2x7w)
16
19
17
20
```jsx
18
21
import { Toggle } from'react-powerplug'
@@ -23,16 +26,37 @@ import Checkbox from './MyDumbCheckbox'
23
26
<Checkbox checked={on} onChange={toggle} />
24
27
)}
25
28
</Toggle>
29
+
30
+
// you can also use a `render` prop instead
31
+
32
+
<Toggle
33
+
initial={false}
34
+
render={({ on, toggle }) => (
35
+
<Checkbox checked={on} onChange={toggle}>
36
+
)}
37
+
/>
26
38
```
27
39
40
+
# Render Props
41
+
42
+
For most people, this may look pretty weird. **But it's extremely powerful**. Usually you render some element whitin your component, but if you are creating an 'agnostic' component or a kind of abstraction component you can not simply render elements, you don't know what the user wants to render. So you render values, actions, states, data... props. You pick these props passing a function to children (or render prop) and now with this data you have total control of what you want to do. Now render what you want to render and do what you want to do. **Render props components are about abstracting some logic without any UI.**
43
+
44
+
React PowerPlug brings to you a bunch of components that act as state and logic containers, so you can get this powerful abstraction and use it any way you want.
45
+
46
+
**Note:** with PowerPlug you can use `children` or `render` prop.
47
+
You decide which one is best for you.
48
+
28
49
# Components
29
50
30
51
***Note:****This is a kind of a cheat sheet for fast search.*
31
-
*If you want a more detailed **API Reference** and examples for each component see the [Docs](docs/README.md)*
52
+
*If you want a more detailed **API Reference** and examples for each component see the [Docs](/docs)*
32
53
33
-
## [State](docs/components/State.md)
34
-
**Props:**`{ initial }`
35
-
**Args:**`{ state, setState }`
54
+
## State Containers
55
+
56
+
### State
57
+
**Component Props:**`{ initial }`
58
+
**Render Props:**`{ state, setState }`
59
+
[see docs](docs/components/State.md)
36
60
37
61
```jsx
38
62
<State initial={{ isLoading:false, data:null }}>
@@ -46,9 +70,10 @@ import Checkbox from './MyDumbCheckbox'
46
70
</State>
47
71
```
48
72
49
-
## [Toggle](docs/components/Toggle.md)
50
-
**Props:**`{ initial }`
51
-
**Args:**`{ on, off, toggle, setOn }`
73
+
### Toggle
74
+
**Component Props:**`{ initial }`
75
+
**Render Props:**`{ on, off, toggle, setOn }`
76
+
[see docs](docs/components/Toggle.md)
52
77
53
78
```jsx
54
79
<Toggle initial={true}>
@@ -58,27 +83,59 @@ import Checkbox from './MyDumbCheckbox'
Because of this, when you use `toggle` function, only `<Toggle>` will be rerendered, but if you use `inc` or `dec` functions, both `<Counter>` and `<Toggle>` will be rerendered. Even using `compose()` utility.
346
+
Because of that, when you use `toggle` function, only `<Toggle>` will be rerendered, but if you use `inc` or `dec` functions, both `<Counter>` and `<Toggle>` will be rerendered. **Even** using `compose()` utility.
347
+
348
+
# CodeSandbox examples
349
+
350
+
[Using Toggle in a Checkbox](https://codesandbox.io/s/jp890p2x7w)
351
+
[Using State in a Pagination](https://codesandbox.io/s/8x9m4893l2)
200
352
201
353
# Install
202
354
@@ -217,4 +369,4 @@ exposed as `ReactPowerPlug`
217
369
# Contribute
218
370
219
371
You can help improving this project sending PRs and helping with issues.
220
-
Also you ping me at [Twitter](http://twitter.com/renatorib_)
372
+
Also you can ping me at [Twitter](http://twitter.com/renatorib_)
0 commit comments