Skip to content

Commit e14e753

Browse files
author
Madeline Trotter
committed
More readme
1 parent 6075310 commit e14e753

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

README.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,36 @@ This is an experimental implementation of React hooks on [react-basic](https://g
66
It's here to allow experimentation while we get feedback on the API and wait for an official React release which supports hooks.
77
For more info on hooks, see [React's documentation](https://reactjs.org/docs/hooks-intro.html).
88

9-
It's also recommended while using this module to use PureScript's new "qualified do" syntax (it's used in the examples, `React.do`).
10-
It's available in the `0.12.2` release.
9+
I recommend using PureScript's new "qualified do" syntax while using this library (it's used in the examples, the `React.do` bits).
10+
It's available in the `0.12.2` compiler release.
1111

12-
If we prefer this API over the existing react-basic API, we may eventually replace it with this.
12+
This library provides the `React.Basic.Hooks` module, which can completely replace the `React.Basic` module.
13+
It borrows a few types from the current `React.Basic` module like `ReactComponent` and `JSX` to make it easy to use both versions in the same project.
14+
If we prefer this API over the existing react-basic API, we may eventually replace `React.Basic` with this implementation.
1315

14-
*A note on Refs:* The `Ref` type is useful for passing to DOM nodes, but while this module remains a small extension to the existing react-basic library it won't be possible to pass a `ref` prop to the native DOM components.
16+
## Example
17+
18+
```purs
19+
mkCounter :: CreateComponent {}
20+
mkCounter = do
21+
component "Counter" \props -> React.do
22+
counter /\ setCounter <- useState 0
23+
24+
React.pure $ R.button
25+
{ onClick: handler_ $ setCounter (_ + 1)
26+
, children: [ R.text $ "Increment: " <> show counter ]
27+
}
28+
```
29+
30+
More examples:
31+
32+
- [Counter with an effect](./examples/counter/src/Counter.purs)
33+
- [Reducer/action-style](./examples/reducer/src/Reducer.purs)
34+
- [Controlled inputs](./examples/controlled-input/src/ControlledInput.purs)
35+
- Components: [Parent](./examples/component/src/Container.purs) and [Child](./examples/component/src/ToggleButton.purs)
36+
- [Refs to DOM nodes](./examples/refs/src/Refs.purs) (and extracting hook logic from a component for reuse)
37+
- [A Todo App](./examples/todo-app/src/TodoApp.purs) (components, inputs, state)
38+
39+
*A note on Refs:* The `Ref` type is useful for all kinds of state (anything which shouldn't trigger a render when changed), particularly references to DOM nodes as in the example.
40+
Unfortunately, while this module remains a small extension to the existing react-basic library it won't be possible to pass a `ref` prop to the native DOM components from `React.Basic.DOM`.
1541
In the meantime, use `element (unsafeCreateDOMComponent "div") { ref: elementRef }`.

0 commit comments

Comments
 (0)