Skip to content

Instantly share code, notes, and snippets.

@rrmdn
Last active January 23, 2021 12:05
Show Gist options
  • Select an option

  • Save rrmdn/9367dcf0361f645bde4807681db86a47 to your computer and use it in GitHub Desktop.

Select an option

Save rrmdn/9367dcf0361f645bde4807681db86a47 to your computer and use it in GitHub Desktop.
import React from 'react'
import qoreContext from "../qoreContext";
export default function Todo() {
const items = qoreContext.views.allTodo.useListRow();
const {
insertRow,
status,
} = qoreContext.views.allTodo.useInsertRow();
const inputRef = React.useRef(null);
return (
<>
<section class="todoapp">
<header class="header">
<h1>todos</h1>
<input
ref={inputRef}
onKeyPress={async (e) => {
if (e.key === "Enter" && status !== 'loading') {
const value = e.currentTarget.value
inputRef.current.value = "";
await insertRow({
name: value,
description: "",
done: false,
});
}
}}
class="new-todo"
placeholder="What needs to be done?"
autofocus
/>
</header>
<section class="main">
<ul class="todo-list">
{(items.data || []).map((item) => (
<li key={item.id} class={item.done && "completed"}>
<div class="view">
<input class="toggle" type="checkbox" checked={item.done} />
<label>{item.name}</label>
<button class="destroy"></button>
</div>
<input class="edit" value="Create a TodoMVC template" />
</li>
))}
</ul>
</section>
</section>
</>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment