# react-x6

> ![npm bundle size](https://img.shields.io/bundlephobia/minzip/react-x6?style=flat-square) ![npm](https://img.shi

Latest version **1.0.8** (published 2023-03-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-x6
pnpm add react-x6
yarn add react-x6
bun add react-x6
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.8 |
| Published | 2023-03-21 |
| First published | 2023-02-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 20.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | lloydzhou |
| Maintainers | lloydzhou |
| Keywords | antv, x6, graph, svg, react, typescript |

## Links

- npm: https://www.npmjs.com/package/react-x6
- Repository: https://github.com/lloydzhou/react-x6
- Issues: https://github.com/lloydzhou/react-x6/issues
- npm.io page: https://npm.io/package/react-x6

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.8 (latest) — 2023-03-21
- 1.0.7 — 2023-03-03
- 1.0.6 — 2023-03-01
- 1.0.5 — 2023-02-27
- 1.0.4 — 2023-02-27
- 1.0.3 — 2023-02-27
- 1.0.2 — 2023-02-27
- 1.0.1 — 2023-02-24
- 1.0.0 — 2023-02-24

## README

# react-x6

<a href="https://www.npmjs.com/package/react-x6"><img alt="NPM Package" src="https://img.shields.io/npm/v/react-x6.svg?style=flat-square"></a>
![npm bundle size](https://img.shields.io/bundlephobia/minzip/react-x6?style=flat-square)
![npm](https://img.shields.io/npm/dm/react-x6?style=flat-square)
<a href="/LICENSE"><img src="https://img.shields.io/github/license/lloydzhou/react-x6?style=flat-square" alt="MIT License"></a>

## 提供自定义渲染器在react中直接渲染x6画布

1. 使用`react-reconciler`自定义渲染器
2. 只需抽象create/update/removeFrom既可
3. 最后渲染出来的instance就是Graph/Node/Edge对象，这些对象使用ref可以直接绑定
4. Graph内部将Children做进一步处理，通过cloneElement强行生成带key的子组件（避免list diff导致元素id变化）

## 安装
```
npm install react-x6
yarn add react-x6
```

## demo

[online demo](https://codesandbox.io/s/react-x6-demo-nhogrp?file=/src/App.js)

```
import { Graph, Node, Edge } from 'react-x6'
import { Snapline } from "@antv/x6-plugin-snapline";

// 使用ElementOfPlugin定义组件
const SnaplinePlugin = ElementOfPlugin('Snapline', Snapline)


export default function App() {
  // ...
  return (
    <Graph background grid width={800} height={600}>
      <SnaplinePlugin key="snapline" enabled={true}/>
      <Node id="1" x={100} y={100} label="node1" width={80} height={40}></Node>
      <Node id="3" x={200} y={100} label="node3" width={80} height={40} parent="1" />
      <Node id="2" x={200} y={200} label="node2" width={80} height={40} />
      <Node id="4" x={200} y={250} label="node4" width={80} height={40} ref={node4} />
      <Node id="5" x={300} y={250} label="node5" width={80} height={40} onClick={e => {
        console.log('onClick', e)
      }} />
      <Edge source="1" target="2" />
    </Graph>
  )
}
```

## TODO
- [x] 提供渲染器
- [x] Graph组件
- [x] Node/Edge组件
- [x] ElementOfPlugin函数方便封装官方plugin
- [x] Label(Edge)
- [x] NodePort
- [x] NodeTool/EdgeTool
- [x] SourceMarker/TargetMarker


## changelog

### 2023-03-22
remove Fragment, using flat array

---
_Source: https://npm.io/package/react-x6 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
