Skip to content
This repository has been archived by the owner on Sep 25, 2023. It is now read-only.

Permission to optionally stop the request

Compare
Choose a tag to compare
@webcarrot webcarrot released this 04 Mar 12:55

React example:

const Component = ({id}: {id:string}) => {
      const api = React.useContext(ApiContext);
      const [obj, setObj] = React.useState<SomeType>(null);
      React.useEffect(() => {
        if (id) {
            const request = api("get/obj", {id});
            request.then(setObj, console.error);
            return () => request.abort();
        }
      }, [id]);
      return obj ? <span>{obj.name}</span> : null;
}