New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

react-sticky-spy

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-sticky-spy

Super minimal `400 byte` css and dependencies free react component that detects and add a custom attribute to a `position: sticky` element when it is stuck inside the scrolling container.

latest
Source
npmnpm
Version
1.3.2
Version published
Maintainers
1
Created
Source

React Sticky Spy

Super minimal 400 byte css and dependencies free react component that detects and add a custom attribute to a position: sticky element when it is stuck inside the scrolling container.

Installation

Install the package with your favourite package manager:

npm i react-sticky-spy
# or
pnpm i react-sticky-spy
# or
yarn add react-sticky-spy

👉 Live Demo

Usage

Import the component and wrap your sticky element. This component doesn't add any wrapper so your markup and style is safe (well, it adds just a empty spy element before but...Hey 👉😎👉, it's free)

The StickySpy component add a custom attribute to the wrapped element so you can control the style using CSS. Additionally, by using the onStickyChange callback you can do your js stuff when the element is stuck or not.

import { StickySpy } from 'react-sticky-spy'

const MyPage = () => (
  <div style={{ overflow: 'auto' }}>
    <StickySpy>
      <h1 style={{ position: 'sticky', top: 0 }}>Position sticky title</h1>
    </StickySpy>
    ...
  <div>
)
h1[data-react-is-sticky="true"] {
  border-bottom: 1px solid gray;
}

Warning The CSS for the sticky position is not included. Add your own style to the wrapped element.

API Reference

export type StickySpyProps = PropsWithChildren<{
  /**
   * Set a custom name for the attribute
   * @default "data-react-is-sticky"
   */
  attribute?: string;
  /**
   * Callback function that is called when the sticky element changes
   * @param isSticky Current state of the sticky element
   */
  onStickyChange?: (isSticky: boolean) => void;
}>

FAQs

Package last updated on 08 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts