Skip to content

Migrating from StPageFlip

The names changed and there’s no compatibility layer for the old ones, so this is a small migration rather than a version bump. The tables below list every option, method, event and React prop the old packages had and where each one went. They’re typed against both APIs, so if a row is here, it’s current.

Swap the dependency first. page-flip becomes the core package and react-pageflip becomes the React one (which needs the core package beside it, and React 19):

Terminal window
npm i @openpageflip/core
Terminal window
npm i @openpageflip/core @openpageflip/react

Then the shape of things, which the tables don’t quite say on their own:

  • new PageFlip(el, opts) followed by loadFromHTML(pages) is one call now, createBook(el, opts). The container’s children are the pages, and the stylesheet is a separate import. The quick start is the full version.
  • The animated turns return a promise that resolves when the page lands, and the getters became plain properties. Everything the old class exposed for its own internals is gone.
  • Event names are the same. The handler gets a typed event with the fields named (e.page, e.orientation, e.state) instead of e.data, and on hands back the unsubscribe function.
  • In React, the ref is the book itself, so ref.current.pageFlip().flipNext() is just ref.current.flipNext(). Pages don’t need refs any more.

Options

page-flipOpenPageFlipNotes
widthwidth
heightheight
sizesize
minWidthminWidth
maxWidthmaxWidth
minHeightremovedHeight follows width by the width:height ratio, so the width bounds are enough.
maxHeightremovedSame as minHeight.
startPagestartPage
flippingTimeflipDuration
drawShadowshadows
maxShadowOpacityshadowOpacity
showCovercover
usePortraitlayoutusePortrait: false is layout: "spread". The default "auto" picks by container width, and "single" is new.
autoSizeautoSize
startZIndexremovedPages are stacked inside the container, so the book no longer needs a z-index base.
mobileScrollSupportremovedThe book sets touch-action on itself, so the page scrolls and the book flips without a flag.
clickEventForwardignoreDragOnClicks on links, buttons and form fields always reach them. ignoreDragOn is the selector that decides which elements never start a flip.
useMouseEventsdragSplit three ways: drag, swipe and click each have their own option.
swipeDistanceswipeDistance
showPageCornershoverCorners
disableFlipByClickclickdisableFlipByClick: true is click: "corners". "off" turns clicks off entirely.

Methods

PageFlipOpenPageFlipNotes
on()book.on()Returns the unsubscribe function, and takes an AbortSignal in its options.
off()book.off()Takes the listener as well as the event name; the old off() dropped every listener of that event.
destroy()book.destroy()
update()book.update()Resizes are watched for you; call this after other layout changes.
loadFromHTML()removedThe container's children are the pages when createBook runs, or pass the pages option.
updateFromHtml()book.setPages()
loadFromImages()removedThere is no image mode. Put an img element on each page and it renders like any other content.
updateFromImages()removedSame as loadFromImages; use setPages with img pages.
clear()removeddestroy() restores the DOM; a new book starts from the pages you give it.
turnToPrevPage()book.turnPrev()
turnToNextPage()book.turnNext()
turnToPage()book.turnTo()
flipNext()book.flipNext()Resolves when the turn lands, with false when there was nothing to turn to.
flipPrev()book.flipPrev()Same promise as flipNext.
flip()book.flipTo()Same promise as flipNext.
getPageCount()book.pageCount
getCurrentPageIndex()book.page
getOrientation()book.orientation
getState()book.state
getBoundsRect()book.rect
getSettings()removedKeep your own options object; the book does not hand it back.
getPage()removedInternal in the old library. The page elements are the ones you passed in.
getRender()removedInternal in the old library.
getFlipController()removedInternal in the old library.
getUI()removedInternal in the old library.
getPageCollection()removedInternal in the old library.
updateState()removedInternal in the old library; state is read-only from outside.
updatePageIndex()removedInternal in the old library; use turnTo or flipTo.
updateOrientation()removedInternal in the old library; the layout option decides orientation.
startUserTouch()removedInternal in the old library; pointer input is handled by the book.
userMove()removedSame as startUserTouch.
userStop()removedSame as startUserTouch.

Events

page-flipOpenPageFlipNotes
initinite.data.page and e.data.mode are now e.page and e.orientation.
updateupdateSame shape as init.
flipflipe.data is now e.page.
changeStatechangeStatee.data is now e.state.
changeOrientationchangeOrientatione.data is now e.orientation.

React props

HTMLFlipBookOpenPageFlipNotes
onInitonInitHandlers get the core event, see the events table.
onUpdateonUpdate
onFliponFlip
onChangeStateonChangeState
onChangeOrientationonChangeOrientation
classNameclassName
stylestyle
childrenchildrenChildren are the pages, as before, but they no longer need a ref or forwardRef. Wrap one in Page to make it hard.
refrefThe ref is the Book itself, so ref.current.flipNext() replaces ref.current.pageFlip().flipNext().
renderOnlyPageLengthChangeremovedPages added or removed by React are picked up after every render, and a changed option rebuilds the book on its own.