Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

updated example todo

awalias9497ffc69597
diff --git a/examples/todo/src/Store.js b/examples/todo/src/Store.js
index 92ee0121cb7..c71b6de0214 100644
--- a/examples/todo/src/Store.js
+++ b/examples/todo/src/Store.js
@@ -16,10 +16,10 @@ export const useStore = (props) => {
fetchList(props.uuid)
.then((response) => {
setList(response)
- setTasks(response.tasks.sort((a, b) => a.id - b.id))
+ setTasks(response.tasks.sort((a, b) => b.id - a.id))
})
.catch(console.error)
- }, [])
+ }, [props.uuid])
useEffect(() => {
const handleAsync = async () => {
@@ -29,12 +29,15 @@ export const useStore = (props) => {
if (task.id === newTask.id) {
tasks[i] = newTask
return true
+ } else {
+ return false
}
})
if (update) {
- setTasks([...tasks]) // update
+ setTasks(t => [...tasks]) // update
} else {
- setTasks(tasks.concat(newTask)) // new
+ tasks.unshift(newTask)
+ setTasks(t => [...tasks]) // new
}
}
}
@@ -51,7 +54,7 @@ export const useStore = (props) => {
.subscribe()
)
}
- }, [list])
+ }, [list, taskListener])
return { list, tasks, setTasks }
}
diff --git a/examples/todo/src/TodoList.js b/examples/todo/src/TodoList.js
index d49fce60adc..91ab17c8c6b 100644
--- a/examples/todo/src/TodoList.js
+++ b/examples/todo/src/TodoList.js
@@ -12,7 +12,7 @@ export const TodoList = (uuid) => {
<h1 className="section">My Task List</h1>
<div className="section">
<label>Sharing url: </label>
- <input type="text" readonly value={window.location.href} />
+ <input type="text" readOnly value={window.location.href} />
</div>
<div className={'field-row section'}>
<form
@@ -27,7 +27,7 @@ export const TodoList = (uuid) => {
value={newTaskText}
onChange={(e) => setNewTaskText(e.target.value)}
/>
- <button type="submit" onClick={() => addTask(newTaskText, list.id)}>
+ <button type="submit" onClick={() => (newTaskText ? addTask(newTaskText, list.id) : '')}>
add task
</button>
</form>
@@ -44,6 +44,8 @@ export const TodoList = (uuid) => {
if (t.id === task.id) {
tasks[i].complete = !task.complete
return true
+ } else {
+ return false
}
})
setTasks([...tasks])
@@ -61,7 +63,9 @@ export const TodoList = (uuid) => {
: ''}
</div>
<div className="section">
- <small>warning: do not store any sensitive information in this list, it is not secure</small>
+ <small>
+ warning: do not store any sensitive information in this list, it is not secure
+ </small>
</div>
</div>
)