Skip to content

Commit 620fe6c

Browse files
authored
Update composable guide reset values (#2511)
* update * update
1 parent 7d93d28 commit 620fe6c

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/guide/reusability/composables.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,16 +216,19 @@ export function useFetch(url) {
216216
const data = ref(null)
217217
const error = ref(null)
218218
219-
const fetchData = (dt) => {
220-
fetch(toValue(url))
219+
const fetchData = () => {
220+
// reset state before fetching..
221+
data.value = null
222+
error.value = null
223+
224+
fetch(toValue(url))
221225
.then((res) => res.json())
222226
.then((json) => (data.value = json))
223227
.catch((err) => (error.value = err))
224-
}
228+
}
225229
226230
watchEffect(() => {
227-
// reset state before fetching..
228-
fetchData(url)
231+
fetchData()
229232
})
230233
231234
return { data, error }

0 commit comments

Comments
 (0)