From 0c098cb581f50e6fa9b35ab808fbcf4b2ae47a2a Mon Sep 17 00:00:00 2001 From: Samuel Meuli Date: Wed, 13 May 2020 19:47:14 +0200 Subject: [PATCH] Initialize font manager after component mount Fixes #29 --- src/FontPicker.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/FontPicker.tsx b/src/FontPicker.tsx index a888a4a..4104cba 100644 --- a/src/FontPicker.tsx +++ b/src/FontPicker.tsx @@ -92,8 +92,12 @@ export default class FontPicker extends PureComponent { sort, }; - // Initialize FontManager object and generate font list + // Initialize FontManager object this.fontManager = new FontManager(apiKey, activeFontFamily, options, onChange); + } + + componentDidMount = (): void => { + // Generate font list this.fontManager .init() .then((): void => { @@ -109,7 +113,7 @@ export default class FontPicker extends PureComponent { console.error("Error trying to fetch the list of available fonts"); console.error(err); }); - } + }; /** * After every component update, check whether the activeFontFamily prop has changed. If so,