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
{{ message }}
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.
The expected behavior is that the loading predicate returned from the useLazyQuery hook should only be false when the data is updated. Since this is used to trigger an effect with useEffect, stale data is used instead of the new data.
The goal is to upload a file using a React-Hooks based component. TinyMCE is used, which takes a file upload handler. The upload requires a URL retrieved from an Apollo Lazy query, which necessitates a useEffect.
constComponent=()=>{const[uploadArgs,setUploadArgs]=useState(null);const[getUploadURL,{ data, loading, error }]=useLazyQuery(GET_UPLOAD_URL);functionuploadFile(/* mocked */){}functionuploadHandler(blob,successCb,failureCb){setUploadArgs([blob,successCb,failureCb]);getUploadURL(blob.blobInfo().fileName);}const[blob,successCb,failureCb]=uploadArgs||[];constuploadURL=data&&data.uploadURL;useEffect(()=>{if(!loading){/** * The second file upload, loading is false, but * uploadURL is the same as the first upload. After * this happens, the data is updated with the new * URL, but it is after the effect is triggered. * The effect is not triggered again. */if(uploadURL&&blob&&successCb&&failureCb){uploadFile(uploadURL,blob,successCb,failureCb);}}},[uploadURL,blob,success,failureCb,loadingCb]);return(<div><EditoruploadHandler={uploadHandler}/></div>);}
The result was that the old URL was used for the second upload (since loading was false), and shortly after (by looking at the output of console.log right after the useLazyQuery hook), the data was updated. The expectation was that the new URL would be present when loading was false in the useEffect.
The expected behavior is that the
loading
predicate returned from theuseLazyQuery
hook should only be false when the data is updated. Since this is used to trigger an effect withuseEffect
, stale data is used instead of the new data.The goal is to upload a file using a React-Hooks based component. TinyMCE is used, which takes a file upload handler. The upload requires a URL retrieved from an Apollo Lazy query, which necessitates a
useEffect
.The result was that the old URL was used for the second upload (since
loading
was false), and shortly after (by looking at the output ofconsole.log
right after theuseLazyQuery
hook), the data was updated. The expectation was that the new URL would be present whenloading
was false in theuseEffect
.Version
The text was updated successfully, but these errors were encountered: