React Archer

4.4.0 · active · verified Sun Apr 19

React Archer is a JavaScript library for drawing dynamic, configurable SVG arrows between any DOM elements within a React application. It is currently at version 4.4.0 and maintains a consistent release cadence, with multiple feature and bugfix releases within recent months, indicating active development. Its primary utility lies in simplifying the visualization of relationships or flows between disparate UI components. Key features include customizable arrow styles (color, width, dash array, curves/angles), support for start/end markers, and the ability to update arrow positions automatically when elements move or resize. It achieves this by managing an SVG layer over your React components, dynamically calculating coordinates based on element anchors. The library supports server-side rendering and provides TypeScript types, making it robust for modern React development.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to set up `ArcherContainer` and `ArcherElement` to draw multiple arrows between React components with custom styling, labels, and anchor points.

import { ArcherContainer, ArcherElement } from 'react-archer';
import React from 'react';

const rootStyle = { display: 'flex', justifyContent: 'center' };
const rowStyle = { margin: '200px 0', display: 'flex', justifyContent: 'space-between' };
const boxStyle = { padding: '10px', border: '1px solid black' };

const App = () => {
  return (
    <div style={{ height: '500px', margin: '50px' }}>
      <ArcherContainer strokeColor="red">
        <div style={rootStyle}>
          <ArcherElement
            id="root"
            relations={[
              {
                targetId: 'element2',
                targetAnchor: 'top',
                sourceAnchor: 'bottom',
                style: { strokeDasharray: '5,5' }
              }
            ]}
          >
            <div style={boxStyle}>Root</div>
          </ArcherElement>
        </div>

        <div style={rowStyle}>
          <ArcherElement
            id="element2"
            relations={[
              {
                targetId: 'element3',
                targetAnchor: 'left',
                sourceAnchor: 'right',
                style: { strokeColor: 'blue', strokeWidth: 1 },
                label: <div style={{ marginTop: '-20px' }}>Arrow 2</div>
              }
            ]}
          >
            <div style={boxStyle}>Element 2</div>
          </ArcherElement>

          <ArcherElement id="element3">
            <div style={boxStyle}>Element 3</div>
          </ArcherElement>

          <ArcherElement
            id="element4"
            relations={[
              {
                targetId: 'root',
                targetAnchor: 'right',
                sourceAnchor: 'left',
                label: 'Arrow 3'
              }
            ]}
          >
            <div style={boxStyle}>Element 4</div>
          </ArcherElement>
        </div>
      </ArcherContainer>
    </div>
  );
};

export default App;

view raw JSON →