diff --git a/src/guide/reusability/composables.md b/src/guide/reusability/composables.md index d2cfffda9f..2633442e79 100644 --- a/src/guide/reusability/composables.md +++ b/src/guide/reusability/composables.md @@ -216,16 +216,19 @@ export function useFetch(url) { const data = ref(null) const error = ref(null) - const fetchData = (dt) => { - fetch(toValue(url)) + const fetchData = () => { + // reset state before fetching.. + data.value = null + error.value = null + + fetch(toValue(url)) .then((res) => res.json()) .then((json) => (data.value = json)) .catch((err) => (error.value = err)) - } + } watchEffect(() => { - // reset state before fetching.. - fetchData(url) + fetchData() }) return { data, error }