Use React.forwardRef for custom Page components
masterIf you want to define your pages as custom React components, you must use React.forwardRef to pass a ref to the underlying DOM element. This allows the HTMLFlipBook engine to interact with the page elements correctly.
const Page = React.forwardRef((props, ref) => {
return (
<div className="demoPage" ref={ref}>
{/* ref required */}
<h1 >Page Header</h1 >
<p>{props.children}</p>
<p>Page number: {props.number}</p>
</div >
);
});
function MyBook(props) {
return (
<HTMLFlipBook width={300} height={500}>
<Page number="1">Page text</Page>
<Page number="2">Page text</Page>
<Page number="3">Page text</Page>
<Page number="4">Page text</Page>
</HTMLFlipBook>
);
}