Skip to content

Commit d6a8eb1

Browse files
committed
Clear response when calling onChange due to url/deps change
1 parent da1fb71 commit d6a8eb1

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/Fetch.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,16 @@ function useFetch(props) {
5050
const fetchFunction =
5151
props.fetchFunction || ((url, options) => fetch(url, options));
5252

53-
useEffect(
54-
() => {
55-
if (isFunction(props.onChange)) {
56-
props.onChange(state);
57-
}
53+
useEffect(() => {
54+
if (isFunction(props.onChange)) {
55+
// Clear the response even if we do not call doFetch immediately
56+
props.onChange({ ...state, response: undefined });
57+
}
5858

59-
if (props.url && !props.manual) {
60-
doFetch(props.url, props.options);
61-
}
62-
},
63-
[props.url, props.manual, ...(props.deps || [])]
64-
);
59+
if (props.url && !props.manual) {
60+
doFetch(props.url, props.options);
61+
}
62+
}, [props.url, props.manual, ...(props.deps || [])]);
6563

6664
function doFetch(url, options, updateOptions) {
6765
if (url == null) {

0 commit comments

Comments
 (0)