Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Font loading issue #42

Closed
gjones604 opened this issue Sep 24, 2020 · 1 comment
Closed

Font loading issue #42

gjones604 opened this issue Sep 24, 2020 · 1 comment

Comments

@gjones604
Copy link

I'm not sure if this is a problem with font-picker-react or just my implementation of it. My app has two font pickers and the user can pick a font and save their selection without any issues. The problem is with trying to load the user's chosen font into FontPicker after they've navigated elsewhere on the app and returned to where the FontPicker is.

The error message that says Uncaught Error: Cannot update active font: "XXXXXXXXX" is not in the font list. This happens about 9 times out of 10 no matter which font is selected.

In my functional react component I'm checking for the activeHeaderFontFamily prop (a string) then setting it into state.

const MyComponent = props => {
    const [activeHeaderFontFamily, setActiveHeaderFontFamily] = useState("");

    useEffect(() => {
        if (props.activeHeaderFontFamily) {
            setActiveHeaderFontFamily(props.activeHeaderFontFamily);
        }
    }, [props]);
    // more code...

And here's how I'm using FontPicker. I pass in the activeFontFamily value directly from state with a fallback to Open Sans.

<FontPicker
    apiKey="XXXXXXXXX"
    activeFontFamily={activeHeaderFontFamily || "Open Sans"}
    limit="300"
    pickerId="header"
    onChange={(nextFont) => setActiveHeaderFontFamily(nextFont.family)}
/>
@gjones604
Copy link
Author

Resolved by implementing FontFaceObserver as demonstrated here: #38

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant