Skip to content

Commit

Permalink
✏️ todo list example
Browse files Browse the repository at this point in the history
  • Loading branch information
astoilkov committed Oct 31, 2024
1 parent 346332c commit 2e3f5da
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,40 @@ export default function Todos() {
}
```

<details>
<summary>Todo list example</summary>
<p></p>

```tsx
import React, { useState } from 'react'
import useDb from 'use-db'

export default function Todos() {
const [todos, setTodos] = useDb('todos', {
defaultValue: ['buy avocado']
})
const [query, setQuery] = useState('')

function onClick() {
setQuery('')
setTodos([...todos, query])
}

return (
<>
<input value={query} onChange={e => setQuery(e.target.value)} />
<button onClick={onClick}>Create</button>
{todos.map(todo => (
<div>{todo}</div>
))}
</>
)
}

```

</details>

<details>
<summary id="remove-item">Removing the data from <code>IndexedDB</code> and resetting to the default</summary>
<p></p>
Expand Down

0 comments on commit 2e3f5da

Please sign in to comment.