Skip to content

Instantly share code, notes, and snippets.

@taras
Last active June 21, 2019 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taras/f635f975fa51fe90d5acde2ae1219d7e to your computer and use it in GitHub Desktop.
Save taras/f635f975fa51fe90d5acde2ae1219d7e to your computer and use it in GitHub Desktop.
import { ReactDOM } from 'react-dom';
import { useTask, useRender } from 'concurrent-react';
const { TaskContext, perform } = useTask(function *(rootElement) {
const render = useRender(ReactDOM);
while (true) {
yield render(<MyApp />, rootElement);
}
});
perform(document.getElementById("root"));
function MyApp() {
const { useState, useTask } = useContext(TaskContext);
const [perform, state] = useTask(function *(n) {
const [count, setCount] = useState(42);
setCount(count + n);
yield timeout(500);
setCount(count + n);
});
return (
<div>
{/** same code goes here **/}
</div>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment