import { useState, useRef } from 'react' import { ReactReader } from '../../lib/index' import type { NavItem, Rendition } from 'epubjs' import { DEMO_URL, DEMO_NAME } from '../components/config' import { Example } from '../components/Example' export const Paging = () => { const [page, setPage] = useState('') const rendition = useRef(undefined) const toc = useRef([]) const [location, setLocation] = useState(0) return ( {page}}> (toc.current = _toc)} locationChanged={(loc: string) => { setLocation(loc) if (rendition.current && toc.current) { const { displayed, href } = rendition.current.location.start const chapter = toc.current.find((item) => item.href === href) setPage( `Page ${displayed.page} of ${displayed.total} in chapter ${ chapter ? chapter.label : 'n/a' }` ) } }} getRendition={(_rendition: Rendition) => { rendition.current = _rendition }} /> ) }