File tree Expand file tree Collapse file tree 1 file changed +17
-9
lines changed
src/content/reference/react Expand file tree Collapse file tree 1 file changed +17
-9
lines changed Original file line number Diff line number Diff line change @@ -907,19 +907,27 @@ import { fetchBio } from './api.js';
907907export 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` ` `
You can’t perform that action at this time.
0 commit comments