UNPKG

1.83 kBSource Map (JSON)View Raw
1{"version":3,"names":["React","MISSING_CONTEXT_ERROR","ScheduleUpdateContext","createContext","scheduleUpdate","Error","flushUpdates","useScheduleUpdate","callback","useContext","useEffect"],"sources":["useScheduleUpdate.tsx"],"sourcesContent":["import * as React from 'react';\n\nconst MISSING_CONTEXT_ERROR = \"Couldn't find a schedule context.\";\n\nexport const ScheduleUpdateContext = React.createContext<{\n scheduleUpdate: (callback: () => void) => void;\n flushUpdates: () => void;\n}>({\n scheduleUpdate() {\n throw new Error(MISSING_CONTEXT_ERROR);\n },\n flushUpdates() {\n throw new Error(MISSING_CONTEXT_ERROR);\n },\n});\n\n/**\n * When screen config changes, we want to update the navigator in the same update phase.\n * However, navigation state is in the root component and React won't let us update it from a child.\n * This is a workaround for that, the scheduled update is stored in the ref without actually calling setState.\n * It lets all subsequent updates access the latest state so it stays correct.\n * Then we call setState during after the component updates.\n */\nexport default function useScheduleUpdate(callback: () => void) {\n const { scheduleUpdate, flushUpdates } = React.useContext(\n ScheduleUpdateContext\n );\n\n scheduleUpdate(callback);\n\n React.useEffect(flushUpdates);\n}\n"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AAEA,MAAMC,qBAAqB,GAAG,mCAA9B;AAEA,OAAO,MAAMC,qBAAqB,gBAAGF,KAAK,CAACG,aAAN,CAGlC;EACDC,cAAc,GAAG;IACf,MAAM,IAAIC,KAAJ,CAAUJ,qBAAV,CAAN;EACD,CAHA;;EAIDK,YAAY,GAAG;IACb,MAAM,IAAID,KAAJ,CAAUJ,qBAAV,CAAN;EACD;;AANA,CAHkC,CAA9B;AAYP;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASM,iBAAT,CAA2BC,QAA3B,EAAiD;EAC9D,MAAM;IAAEJ,cAAF;IAAkBE;EAAlB,IAAmCN,KAAK,CAACS,UAAN,CACvCP,qBADuC,CAAzC;EAIAE,cAAc,CAACI,QAAD,CAAd;EAEAR,KAAK,CAACU,SAAN,CAAgBJ,YAAhB;AACD"}
\No newline at end of file