Nodlik / react-pageflip

Simple React.js wrapper for StPageFlip library, for creating realistic and beautiful page turning effect
https://nodlik.github.io/react-pageflip/
MIT License
476 stars 91 forks source link

All the optional props are required #32

Open marked29 opened 2 years ago

marked29 commented 2 years ago

Hello

I used react-pageflip on my pet project which was written in ReactJS using TypeScript as well and there was one problem regarding props . Documentation says that the only required props for HTMLFlipBook are width and height but in real use it turned out that not only these props are required.

I checked node_modules/react-pageflip and it turned out that a lot of props are required indeed. I provided local solution for my project but I reckon that some changes should happen in original code base that it could correspond to the documentation and not to be confusing.

I can fix the issue if you want me to fix it.

Best regards, Mark

YoonJeongLulu commented 2 years ago

How can I see your local solution?

aldrichdev commented 2 years ago

I am also getting this issue.

image

I imported HTMLFlipbook like this:

import HTMLFlipBook from 'react-pageflip'

Even if I add all the required properties with default values, I get an error Invalid flipping time once the PDF loads.

umair-dmechs commented 1 year ago

Getting the same issue. You must have to make the optional props to be optional props. currently, almost every prop is a required prop.

Screenshot 2023-01-10 at 5 05 58 PM
ghost commented 9 months ago

I figured this out this problem and, until this gets fixed, the only workaround is to override the types yourself. I did this by importing the types itself and extending it to an interface then wrapping it with a Partial generic works.

Here's a hack I've haphazardly implemented of getting most the types to be optional in Next.js:

"use client"

import dynamic from "next/dynamic"
import type { IEventProps, IFlipSetting } from "react-pageflip/build/html-flip-book/settings"

interface HTMLFilpPageOverride extends Partial<IFlipSetting & IEventProps> {
  className?: string
  style?: React.CSSProperties
  children: React.ReactNode
  renderOnlyPageLengthChange?: boolean
  ref?: any
}

const HTMLFlipBook = dynamic(() => import("react-pageflip"), {
  ssr: false
}) as React.ComponentType<HTMLFilpPageOverride>

export default function BookWrapper() {
  return (
    <HTMLFlipBook width={300} height={500}>
      <div className="demoPage">Page 1</div>
      <div className="demoPage">Page 2</div>
      <div className="demoPage">Page 3</div>
      <div className="demoPage">Page 4</div>
    </HTMLFlipBook>
  )
}
bstevary commented 5 months ago

since 2022, no one has close this issue, it should be marked as a bug. I have been force several time to follow what typescript need