Skip to content

Instantly share code, notes, and snippets.

@bradfordlemley
Created May 29, 2019 22:54
Show Gist options
  • Save bradfordlemley/fddb02cf32deea56fa31e2816a00f425 to your computer and use it in GitHub Desktop.
Save bradfordlemley/fddb02cf32deea56fa31e2816a00f425 to your computer and use it in GitHub Desktop.
Functional App component using "use"
import { use } from '@stated-library/react';
import { appState$ } from './state';
const App = () => {
const {addTodo, allTodos, visibleTodos} = use(appState$);
return (
<>
<button onClick={() => addTodo("New todo")}>
Add Todo
</button>
<div>All todos: {allTodos.map(todo => <div>{todo.title}</div>)}</div>
<div>Visible todos: {visibleTodos.map(todo => <div>{todo.title}</div>)}</div>
</>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment