Open
Description
useEffect
is a common way to load async data right now in React. useEffect
supports watching specific dependencies.
const [value, setValue] = useState();
useEffect(() => {
setData(myFetchFn({ value });
return cancel;
}, [value]);
Now if I update value
, I automatically get updated data.
react-async
supports something similar
const [value, setValue] = useState();
const { data } = useAsync({ promiseFn: myFetchFn, value, watch: value })
However, when I first did this, I expected watch to follow useEffect
's syntax of passing an array of dependencies rather than it watching the primitive value. ex: watch: [value]
It would be great if react-async
treated an array being passed in to watch
similar to the dependency array in useEffect
as it's a little confusing coming from useEffect
why passing an array causes an infinite render loop.