`rc-align` is a React UI component designed for precise element alignment within a web page, acting as a React wrapper for the `dom-align` library. It enables dynamic positioning of a child element relative to a target, supporting various target types including other DOM elements or specific page coordinates. The current stable version is 4.0.15, with a v5 pre-release indicating upcoming architectural changes. The library maintains a moderate release cadence, addressing bugs and adding features periodically. Key differentiators include its robust underlying `dom-align` logic, support for realigning on window resize, and a focus on providing a declarative React interface for complex positioning scenarios. It ships with TypeScript types for improved developer experience and integrates seamlessly into React applications requiring dynamic UI positioning.
npm install rc-alignVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `rc-align` to position a 'source' React element relative to a 'target' DOM element. It utilizes `useRef` for element references, configures alignment points, an offset, and enables realignment on window resize.
While `rc-align` aims to abstract this change, review your `align` configuration objects and any direct usage of `dom-align` if you are upgrading to v5.
Upgrade to `rc-align` version 4.0.13 or newer to ensure better compatibility and stability in React Strict Mode.
Consult the `rc-align` and `dom-align` documentation for specific API changes and update your `align` prop configuration objects accordingly.
Upgrade to `rc-align` version 4.0.9 or newer to resolve issues with `onAlign` callback consistency and accuracy.
Upgrade to `rc-align` version 4.0.14 or later to fix SSR rendering problems related to improper element validation.
Ensure the target element referenced by `targetRef.current` (or similar) is fully mounted and available in the DOM when `rc-align` attempts to perform alignment. You might need to add a conditional render or a `useEffect` hook to defer alignment until the target is ready.
Upgrade to `rc-align` v4.0.9 or later. Also, ensure that the `align` prop is a stable object or memoized if it's not strictly changing, to avoid unnecessary re-renders and re-alignments.
Set the `monitorWindowResize` prop to `true` on the `Align` component: `<Align monitorWindowResize={true} ... />`.