> For the complete documentation index, see [llms.txt](https://projectstorm.gitbook.io/react-diagrams/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://projectstorm.gitbook.io/react-diagrams/getting-started/using-the-library.md).

# Using the library

## Using Typescript

If you are using typescript, then you are in luck! The library is built in typescript, and includes advanced types for everything you need right out of the box.

Lets start by including the things we are going to need:

```typescript
import createEngine, { 
    DefaultLinkModel, 
    DefaultNodeModel,
    DiagramModel 
} from '@projectstorm/react-diagrams';

import {
    CanvasWidget
} from '@projectstorm/react-canvas-core';
```

Now we call `createEngine` which will bootstrap a **DiagramEngine** for us that contains all the defaults setup.

```typescript
// create an instance of the engine with all the defaults
const engine = createEngine();
```

Next, we create two nodes:

```typescript
// node 1
const node1 = new DefaultNodeModel({
    name: 'Node 1',
    color: 'rgb(0,192,255)',
});
node1.setPosition(100, 100);
let port1 = node1.addOutPort('Out');

// node 2
const node2 = new DefaultNodeModel({
    name: 'Node 1',
    color: 'rgb(0,192,255)',
});
node2.setPosition(100, 100);
let port2 = node2.addOutPort('Out');
```

Now we link the two ports of both of the nodes:

```typescript
// link them and add a label to the link
const link = port1.link<DefaultLinkModel>(port2);
link.addLabel('Hello World!');
```

Great! Now we have setup a simple diagram. All thats left to do, is create a **DiagramModel** to contain everything, add all the elements to it, and then add it to the engine.

```typescript
const model = new DiagramModel();
model.addAll(node1, node2, link);
engine.setModel(model);
```

And then we render with **React**!

```jsx
<CanvasWidget engine={engine} />
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://projectstorm.gitbook.io/react-diagrams/getting-started/using-the-library.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
