首页 > 解决方案 > 如何将自定义 fontFamily 添加到 reacr-reader npm

问题描述

我正在使用 react-reader npm,但无法将自定义字体系列放入我的项目中。有谁知道这个答案?

https://www.npmjs.com/package/react-reader

标签: javascriptreactjsreaderepub.js

解决方案


import React, { useState,useRef } from "react"
import { ReactReader } from "react-reader"

const App = () => {
  const [location, setLocation] = useState(null)
  const renditionRef = useRef(null);

  return (
    <div style={{ height: "100vh" }}>
      <ReactReader
        location={location}
        locationChanged={ (epubcifi)=>setLocation(epubcifi)}
        url="https://gerhardsletten.github.io/react-reader/files/alice.epub"
        getRendition={(rendition) => {
                renditionRef.current = rendition;
                renditionRef.current.themes.register('custom', {
                  p: {
                   'font-family': `Helvetica`,

                  },
                });
               renditionRef.current.themes.select('custom');
              }}
      />
    </div>
  )
}

export default App

推荐阅读