11import scratchProjectSave from "../../utils/scratchProjectSave.js" ;
2- import { useCallback } from "react" ;
2+ import { useCallback , useRef } from "react" ;
33
44import WrapperdScratchGui from "./WrappedScratchGui.jsx" ;
55import { postScratchGuiEvent } from "./events.js" ;
@@ -30,13 +30,13 @@ const handleScratchGuiAlert = (alertType) => {
3030 }
3131} ;
3232
33- let scratchFetchApi = null ;
34-
3533const ScratchEditor = ( { projectId, locale, apiUrl, accessToken } ) => {
34+ const scratchFetchApiRef = useRef ( null ) ;
35+
3636 const handleUpdateProjectData = useCallback (
3737 async ( currentProjectId , vmState , params ) => {
3838 return scratchProjectSave ( {
39- scratchFetchApi,
39+ scratchFetchApi : scratchFetchApiRef . current ,
4040 apiUrl,
4141 currentProjectId,
4242 vmState,
@@ -55,9 +55,9 @@ const ScratchEditor = ({ projectId, locale, apiUrl, accessToken }) => {
5555 assetHost = { `${ apiUrl } /api/scratch/assets` }
5656 basePath = { `${ process . env . ASSETS_URL } /scratch-gui/` }
5757 onStorageInit = { ( storage ) => {
58- scratchFetchApi = storage . scratchFetch ;
58+ scratchFetchApiRef . current = storage . scratchFetch ;
5959 if ( accessToken ) {
60- scratchFetchApi . setMetadata ( "Authorization" , accessToken ) ;
60+ scratchFetchApiRef . current . setMetadata ( "Authorization" , accessToken ) ;
6161 }
6262 } }
6363 onUpdateProjectData = { handleUpdateProjectData }
0 commit comments