Skip to content

Commit d57370e

Browse files
committed
docs: draft first suggestion
1 parent c76a1f7 commit d57370e

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/content/reference/react/useEffect.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -907,19 +907,27 @@ import { fetchBio } from './api.js';
907907
export default function Page() {
908908
const [person, setPerson] = useState('Alice');
909909
const [bio, setBio] = useState(null);
910+
const [isLoading, setIsLoading] = useState(false)
911+
const [error, setError] = useState(null)
910912

911913
useEffect(() => {
912-
let ignore = false;
913-
setBio(null);
914-
fetchBio(person).then(result => {
915-
if (!ignore) {
916-
setBio(result);
914+
let ignore = false
915+
setIsLoading(true)
916+
setError(null)
917+
setBio(null)
918+
fetchBio(person).then(s => {
919+
if(!ignore){
920+
setBio(s)
917921
}
918-
});
922+
}).catch(s => setError(s))
923+
.finally(() => setIsLoading(false))
924+
919925
return () => {
920-
ignore = true;
921-
};
922-
}, [person]);
926+
ignore = true
927+
}
928+
},[person])
929+
930+
}
923931

924932
// ...
925933
```

0 commit comments

Comments
 (0)