Skip to content

Commit

Permalink
readme: mwe link
Browse files Browse the repository at this point in the history
  • Loading branch information
elbywan committed Jun 10, 2019
1 parent 8000939 commit 7a57898
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ Inspired by [react-apollo](https://github.com/apollographql/react-apollo).

#### Minimal working example

[Hosted here.](https://elbywan.github.io/hyperactiv/mwe/react.html)

```html
<!DOCTYPE html>
<html>
Expand All @@ -161,6 +163,8 @@ Inspired by [react-apollo](https://github.com/apollographql/react-apollo).
const store = createStore({ todos: {} })
// `watch()` wraps components so that they will get re-renders on store change.
// Even if it is <TodoDetails /> that loads the data, <TodoTitle />
// will be re-rendered whenever needed.
const TodoTitle = watch(() =>
<p>
{ store.todos[1] &&
Expand All @@ -171,7 +175,10 @@ Inspired by [react-apollo](https://github.com/apollographql/react-apollo).
</p>
)
// Same with <TodoDetails />, whenever <TodoTitle /> changes the title,
// this component will be re-rendered.
const TodoDetails = watch(() => {
// Fetch data from the network since the cache is empty at first.
const { data: todo, loading, refetch } = useResource(
'todos',
'https://jsonplaceholder.typicode.com/todos/1',
Expand Down

0 comments on commit 7a57898

Please sign in to comment.