Documentation
External
Hooks
useIndexes

useIndexes

Description

The useIndexes hook is a custom React hook designed to provide the current story and page indexes along with a boolean indicating if the current story and page are the ones being viewed. This hook is particularly useful in scenarios where you need to track or display the active story and page within a storytelling or slideshow component.

Return Values

PropertyTypeDescription
pageobjectThe information about of the page from which it is called.
storyobjectThe information about of the story from which it is called.

Object

PropertyTypeDescription
currentbooleanIndicates if the current component are being viewed.
indexnumberThe index of the component from which it is called.
import { useIndexes } from "@react-instastories/base";
 
function InnerPageContent() {
  const { page, story } = useIndexes();
 
  return (
    <div>
      <p>Current Story: {story.index}</p>
      <p>Current Page: {page.index}</p>
      <p>
        {page.current
          ? "This is the current story and page."
          : "This is not the current story and page."}
      </p>
    </div>
  );
}