Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

react-insta-stories

> 前端框架
Open source

A React component for Instagram like stories

1.5K stars0 likes1 views
WebsiteGitHub

About

A React component for Instagram like stories

react-insta-stories

A React component for Instagram like stories

Homepage • Discord


Install

bash
npm install --save react-insta-stories

Demo

The component responds to actions like tap on right side for next story, on left for previous and tap and hold for pause. Custom time duration for each story can be provided. See it in action here: https://mohitk05.github.io/react-insta-stories/

Usage

javascript
import React, { Component } from 'react';

import Stories from 'react-insta-stories';

const App = () => {
	return (
		<Stories
			stories={stories}
			defaultInterval={1500}
			width={432}
			height={768}
		/>
	);
};

Here stories is an array of story objects, which can be of various types as described below.

Props

Property Type Default Description
stories [String/Object] required An array of image urls or array of story objects (options described below)
renderers ⚡️ [Object] [] An array of renderer objects (options described below)
defaultInterval Number 1200 Milliseconds duration for which a story persists
loader Component Ripple loader A loader component as a fallback until image loads from url
header Component Default header as in demo A header component which sits at the top of each story. It receives the header object from the story object. Data for header to be sent with each story object.
storyContainerStyles Object {} Styles object for the outer container
width Number/String 360 Width of the component, e.g. 600 or '100vw' or 'inherit'
height Number/String 640 Height of the component, e.g. 1000 or '100%' or 'inherit'
storyStyles Object none Override the default story styles mentioned below.
progressContainerStyles Object {} Styles object for the container wrapping the progress bars
progressWrapperStyles Object {} Styles object for the container wrapping each progress bar bars
progressStyles Object {} Styles object for the progress bars
loop Boolean false The last story loop to the first one and restart the stories.
New props ⭐️ ⭐️ ⭐️
isPaused Boolean false Toggle story playing state
currentIndex Number undefined Set the current story index
onStoryStart Function - Callback when a story starts
onStoryEnd Function - Callback when a story ends
onAllStoriesEnd Function - Callback when all stories in the array have ended
onNext Function - Callback when the user taps/press to proceed to the next story
onPrevious Function - Callback when the user taps/press to go back to the previous story
keyboardNavigation Boolean false Attaches arrow key listeners to navigate between stories if true. Also adds up arrow key listener for opening See More and Escape/down arrow for closing it
preventDefault Boolean false Disable the default behavior when user click the component
preloadCount number 1 Determines how many stories should be preloaded ahead of the current story index.

Story object

Instead of simple string url, a comprehensive 'story object' can also be passed in the stories array.

Property Description
url The url of the resource, be it image or video.
type Optional. Type of the story. `type: 'video'
duration Optional. Duration for which a story should persist.
header Optional. Adds a header on the top. Object with heading, subheading and profileImage properties.
seeMore Optional. Adds a see more icon at the bottom of the story. On clicking, opens up this component. (v2: updated to Function instead of element)
seeMoreCollapsed Optional. Send custom component to be rendered instead of the default 'See More' text.
styles Optional. Override the default story styles mentioned below.
preloadResource Optional. Whether to preload the resource or not, defaults to true for images and false for videos (video preloading is experimental)

Default story styles

Following are the default story content styles. Override them by providing your own style object with each story or a global override by using the storyStyles prop.

javascript
storyContent: {
    width: 'auto',
    maxWidth: '100%',
    maxHeight: '100%',
    margin: 'auto'
}

Renderers

To allow reusable components to display story UI, you can pass in pre-built or custom-built components in a special manner to leverage this behavior. Each renderer object has two properties:

  • renderer - This is the UI component that will be rendered whenever the object matches certain conditions.
  • tester - This is a function that tests whether the renderer is suitable for the current story. It receives the current story object to render and returns an object with two properties:
    • condition - This states if the renderer matches the current story's criteria (a boolean).
    • priority - A number denoting the priority of the current renderer. E.g. priority of 2 is less than a 5, and if two renderers have condition = true, their priorities will be compared and the one with higher priority will be selected.

So essentially a simple renderer would look like this: (you may also refer the inbuilt Image renderer)

javascript
// Renderer.js

export const renderer = ({ story, action, isPaused, config }) => {
	return 
;
};

export const tester = (story) => {
	return {
		// Use this renderer only when the story type is video
		condition: story.type === 'video',
		priority: 3,
	};
};

Every renderer component gets 4 props as shown above. Out of these the story, action and isPaused are as their names suggest. The config object contains certain global properties which were passed while initialising the component. It looks like this:

javascript
const { width, height, loader, storyStyles } = config;

These props can be used to customize the entire UI as required, and then can be packaged as a Node module and shared. If someone else wishes to use your package as a renderer, they can simply pass it inside an array as the renderers prop to the main component. If you publish any such renderer, please raise a PR to add it to this list. A few suggestions would be a Markdown renderer, highlighted code renderer, etc.

List of public renderers:

  • Add one here

Higher Order Components

WithSeeMore

This is a wrapper component which includes the UI and logic for displaying a 'See More' link at the bottom of the story. This is available as a named export from the package and can be used to easily add the functionality to a custom content story. It takes in two props - story and action.

javascript
const { WithSeeMore } from 'react-insta-stories';

const CustomStoryContent = ({ story, action }) => {
	return <WithSeeMore story={story} action={action}>
		

	</WithSeeMore>
}

You can also send custom 'See M

Issues· 144 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScriptinstagramreactreact-componentsstories

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category前端框架
PricingOpen source

> Related tools

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架