Skip to content

Commit bf64c8d

Browse files
add prop to counter example
1 parent aed7ddc commit bf64c8d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

examples/counter/counter.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@ import React from 'react';
22
import ReactDOM from 'react-dom';
33
import Coroutine from '../../src/Coroutine';
44

5-
async function Counter({ counter, forceUpdate }) {
5+
function getVariables() {
6+
return { counter: 0 };
7+
}
8+
9+
async function Counter({ name, counter, forceUpdate }) {
610
return (
711
<section>
812
<button onClick={() => forceUpdate({ counter: counter + 1 })}>
913
increment
1014
</button>
1115

1216
<output>
13-
{counter}
17+
{name}: {counter}
1418
</output>
1519
</section>
1620
);
1721
}
1822

19-
const CounterCo = Coroutine.create(Counter, () => ({ counter: 0 }));
23+
const CounterCo = Coroutine.create(Counter, getVariables);
2024

21-
ReactDOM.render(<CounterCo />, document.querySelector('main'));
25+
ReactDOM.render(<CounterCo name="Things count" />, document.querySelector('main'));

0 commit comments

Comments
 (0)