fix(app.tsx): add safe check for readyPromise (#2489)

* fix(app.tsx): add safe check for readyPromise

* make type-safe

Co-authored-by: dwelle <luzar.david@gmail.com>
This commit is contained in:
Aakansha Doshi 2020-12-09 01:35:08 +05:30 committed by GitHub
parent fba37e422d
commit 8f8fd023f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 8 deletions

View file

@ -301,9 +301,9 @@ class App extends React.Component<ExcalidrawProps, AppState> {
};
if (excalidrawRef) {
const readyPromise =
typeof excalidrawRef === "function"
? resolvablePromise<ExcalidrawImperativeAPI>()
: excalidrawRef.current!.readyPromise;
("current" in excalidrawRef && excalidrawRef.current?.readyPromise) ||
resolvablePromise<ExcalidrawImperativeAPI>();
const api: ExcalidrawImperativeAPI = {
ready: true,
readyPromise,