React Aptor is a minimal API connector for React applications, currently at version 2.0.0. It provides a structured and opinionated way to integrate vanilla JavaScript third-party libraries, especially those that interact directly with the DOM, into React components. The library addresses common integration challenges such as finding DOM nodes, preventing excessive re-renders, and managing API lifecycles without relying on global scope or introducing unnecessary abstraction layers. Emphasizing a "zero-dependency," "tree-shakeable," and "side-effect free" design, React Aptor boasts a minimal bundle size (less than 1 kilobyte). While a strict release cadence is not specified, recent updates, including the significant v2.0.0 release, indicate active development focused on improving the build process, testing infrastructure, and project consistency. Its core differentiator is empowering developers with full control over their API definitions and their connection to React, aiming to be anti-pattern-free within the React ecosystem.
npm install react-aptorVerified import paths — ran on the pinned version, not inferred.
Demonstrates connecting a custom 'CounterLib' third-party library to a React component using `useAptor` by defining `instantiateCounter` and `getCounterAPI` functions, then consuming the exposed API.
Ensure your `instantiate` function's return type correctly reflects the `destroy` function as optional if it's not always present.
Review components that pass refs to `useAptor`-managed elements. Ensure ref handling aligns with modern React `forwardedRef` patterns, especially if you encountered TypeScript errors related to refs.
Pass a `useRef` hook's current value (e.g., `containerRef.current`) as the node argument to your `instantiate` function via `useAptor`, rather than using `ReactDOM.findDOMNode` to locate the DOM element.
Consult the official `react-aptor` GitHub repository's changelog for a comprehensive list of changes when upgrading to v2.0.0 or later to identify potential API-level breaking changes.
Ensure `useAptor` is only called at the top level of a React function component or another custom React hook (e.g., not inside loops, conditions, or nested functions).
Verify that your `getAPI` function correctly accesses and exposes all desired methods from the `instance` argument. Debug the `instance` object within `getAPI` to confirm the availability of methods.
Ensure the `useRef` is properly initialized with `null` and then attached to a real DOM element (e.g., `<div ref={containerRef}></div>`). The `useAptor` hook internally handles the lifecycle, so just ensure the ref is placed correctly.