react-stick is a React component library designed to facilitate the 'sticking' of an absolutely positioned React node (often a tooltip, dropdown, or modal) to a dynamically positioned anchor element. It achieves this by rendering the 'stuck' node in a React Portal, typically as a direct child of the `body` element, ensuring it's not affected by the anchor's parent overflow or styling. The current stable version is `5.0.7`, with releases appearing to be semantically versioned and somewhat regular, addressing bug fixes and minor enhancements. A key differentiator is its focus on robust positioning logic, including automatic flipping based on available viewport space, and its recent migration to TypeScript for improved developer experience and type safety. It requires React and ReactDOM `>=16.8.0`.
npm install react-stickVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to use the `Stick` component to attach a 'stick node' (a red-bordered paragraph) to an 'anchor node' (a blue-bordered paragraph), positioning it based on specified `position` and `align` props. The stick node will follow the anchor node even on scroll, appearing outside its parent flow.
If your project relies on FlowJS for type checking with `react-stick`, you will need to either migrate your project to TypeScript or downgrade to a version prior to 5.0.0. Ensure your build pipeline supports TypeScript for consuming the library.
Upgrade to `react-stick` version `5.0.6` or newer to ensure proper functionality with SSR. This version includes a fix for SSR compatibility.
Update to `react-stick` version `4.1.2` or higher, which includes performance improvements by adding an `enabled` flag to `useWatcher` to prevent unnecessary recalculations.
Upgrade to `react-stick` version `4.1.4` or newer to ensure that changes to `align` and `position` props are correctly applied, even when auto-flipping logic is engaged.
Update to `react-stick` version `4.1.3` or newer. This version includes a fix to check alignment on the first render, not just on scroll, ensuring correct initial positioning.
Ensure you are using `import Stick from 'react-stick';` for ESM environments. If in a CommonJS context, verify your build tooling (e.g., Webpack, Babel) is correctly transpiling ESM imports. Consider updating your build setup to a more modern configuration that supports ESM.
This issue was specifically addressed in `react-stick` version `5.0.6`. Upgrade to `react-stick@5.0.6` or newer. Additionally, ensure your SSR setup is correctly handling portals and dynamic styling.
Ensure you are using `react-stick` version `5.0.0` or newer, as this version introduced TypeScript types. If you are on an older version, you might not have types. If on v5+, clear your `node_modules` and `package-lock.json` and reinstall to ensure correct type resolution. Also, double-check the prop names against the documentation.