Skip to content

Commit 49b9091

Browse files
niklubcursoragentcaitlinwheeless
authored
docs: ReactCode src attribute documentation (#9416)
Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: niklub <niklub@users.noreply.github.com> Co-authored-by: Caitlin <caitlin@humansignal.com>
1 parent 0af563d commit 49b9091

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

docs/source/tags/reactcode.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ Importantly, this allows you to continue leveraging Label Studio's annotation ma
2121
| Parameter | Type | Default | Description |
2222
|-----------|------|---------|-------------|
2323
| name | string || Unique identifier for the tag (required) |
24-
| [toName] | string || If this is a [self-referencing tags ](#Self-referencing-tag), this parameter is required and should match `name` |
24+
| [toName] | string || If this is a [self-referencing tag](#Self-referencing-tag), this parameter is required and should match `name` |
2525
| [data] | string || The [task data](#Data-parameter), e.g., `data="$image"` or `data="$text"` |
26+
| [src] | string || URL to an external JavaScript file containing the React component code. Use this as an alternative to inline code. [See more below](#Using-the-src-attribute) |
2627
| [inputs] | string || Defines the JSON schema for the input data (`data`) |
2728
| [outputs] | string || Defines the JSON schema for the [output](#Using-the-outputs-parameter) |
2829
| [style] | string || Inline styles or CSS string for the iframe container |
@@ -66,7 +67,37 @@ function MyComponent({ React, addRegion, regions, data }) {
6667
}
6768
```
6869

70+
### Using the `src` attribute
6971

72+
By default, you write your React component code inline, directly inside the `<ReactCode>` tag (typically wrapped in a [CDATA section](#CDATA-wrapper)). The `src` attribute provides an alternative approach: instead of embedding the code in the labeling configuration, you can host it at an external URL and reference it.
73+
74+
This works similarly to how a `<script src="...">` tag loads JavaScript from an external file in HTML.
75+
76+
```xml
77+
<!-- Instead of inline code... -->
78+
<ReactCode name="custom" toName="custom" data="$myData">
79+
<![CDATA[
80+
function MyComponent({ React, addRegion, regions, data }) {
81+
// ... your code here
82+
}
83+
]]>
84+
</ReactCode>
85+
86+
<!-- ...you can reference an external file -->
87+
<ReactCode name="custom" toName="custom" data="$myData" src="https://example.com/my-component.js" />
88+
```
89+
90+
The external JavaScript file should export a function component with the same signature as inline code (receiving `React`, `addRegion`, `regions`, `data`, and `viewState` as props).
91+
92+
**When to use `src`:**
93+
94+
- Your component code is large or complex and difficult to manage inside XML
95+
- You want to version and maintain your UI code in a separate repository
96+
- You want to reuse the same component across multiple labeling projects
97+
- You prefer developing in a standard IDE workflow (edit, deploy, reference)
98+
99+
!!! note
100+
When the `src` attribute is provided, any inline code inside the `<ReactCode>` tag is ignored. The component is loaded entirely from the external URL.
70101

71102
## React usage notes
72103

0 commit comments

Comments
 (0)