Skip to content

Commit 3388785

Browse files
committed
Update composables.md (vuejs#2473)
Modifying data.value and error.value within watchEffect has the potential to trigger infinite re-renders.
1 parent 18836e9 commit 3388785

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/guide/reusability/composables.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,16 @@ export function useFetch(url) {
216216
const data = ref(null)
217217
const error = ref(null)
218218
219-
watchEffect(() {
220-
// restablecer el estado antes de la recuperación..
221-
data.value = null
222-
error.value = null
223-
// toValue() desenvuelve potenciales refs o getters
219+
const fetchData = (dt) => {
224220
fetch(toValue(url))
225221
.then((res) => res.json())
226222
.then((json) => (data.value = json))
227223
.catch((err) => (error.value = err))
224+
}
225+
226+
watchEffect(() {
227+
// restablecer el estado antes de la recuperación..
228+
fetchData(url)
228229
})
229230
230231
return { data, error }

0 commit comments

Comments
 (0)