font-picker-react
font-picker-react copied to clipboard
after install npm its wok in client side but getting error in server side like . ReferenceError: document is not defined
ReferenceError: document is not defined
at /Users/shopcratshopcrat/Documents/Dixit/React/Apcrat Projects/shoppiko/admin/node_modules/@samuelmeuli/font-manager/dist/index.js:164:34
at __assign (/Users/shopcratshopcrat/Documents/Dixit/React/Apcrat Projects/shoppiko/admin/node_modules/@samuelmeuli/font-manager/dist/index.js:2:68)
at Object.
plz help
Same issue over here
@ReactRambo You should disable SSR (server side rendering) for this component. For example, if you're using next.js, you'd import this module like this:
import dynamic from 'next/dynamic';
const FontPicker = dynamic(() => import('font-picker-react'), { ssr: false });
Then you can use <FontPicker ... /> like any other React component.
A bit late but the way I fix it is go into node_modules, find this library and in index.es.js/index.js change
var previewFontsStylesheet = document.createElement("style");
document.head.appendChild(previewFontsStylesheet);
to
if(typeof document !== 'undefined'){
var previewFontsStylesheet = document.createElement("style");
document.head.appendChild(previewFontsStylesheet);
}
Would be great if the library itself had this implemented.
For use with react ES6 I used:
//import FontPicker from "font-picker-react";
import loadable from "@loadable/component";
const FontPicker = loadable(() => import("font-picker-react"));