prevent page reload and split code

This commit is contained in:
cupcakearmy
2019-05-24 15:52:20 +02:00
parent 55adfdf587
commit 02559d89ab
2 changed files with 22 additions and 23 deletions

View File

@@ -17,11 +17,16 @@ const List = ({ fetched }) => {
input.current.focus()
}, [input])
const _submit = () => callAPI(null, {
url: `/api/items/`,
method: 'post',
data: { text },
}).then(refresh)
const _submit = async (e) => {
e.preventDefault()
await callAPI(null, {
url: `/api/items/`,
method: 'post',
data: { text },
})
setText('')
refresh()
}
const _clear = () => callAPI(null, {
url: `/api/items/`,