You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently you use useEffect in usePromise to call the async function, unfortunately Raycast uses React strict mode in development and all useEffect are called twice.
Here is a simple extension to reproduce the issue:
import{useCachedPromise,usePromise}from"@raycast/utils";import{Action,ActionPanel,List}from"@raycast/api";exportdefaultfunctionCommand(){const{ isLoading, data }=usePromise(async()=>{console.log("Inside usePromise");return{};});const{isLoading: isLoadingCached}=useCachedPromise(async()=>{console.log("Inside useCachedPromise");return{cachedData: "This is cached data"};});return(<ListisLoading={isLoading||isLoadingCached}><List.Itemtitle="Result"subtitle={JSON.stringify(data)}actions={<ActionPanel><Action.CopyToClipboardcontent={JSON.stringify(data)}/></ActionPanel>}/></List>);}
I propose using a simple ref to track the time the promise was called. Then if the promise was already called in the last 10 milliseconds, skip running it again.
The text was updated successfully, but these errors were encountered:
Currently you use
useEffect
inusePromise
to call the async function, unfortunately Raycast uses React strict mode in development and all useEffect are called twice.Here is a simple extension to reproduce the issue:
Here is the generated logs:
I propose using a simple ref to track the time the promise was called. Then if the promise was already called in the last 10 milliseconds, skip running it again.
The text was updated successfully, but these errors were encountered: