2024-11-10 22:27:25 +00:00
---
id: custom-component
title: Custom Component
---
2025-04-21 06:26:21 +00:00
ToolJet allows you to create your own React component using the **Custom Component** , providing greater flexibility and customization for your application. The **Custom Component** has two main properties:
2024-11-10 22:27:25 +00:00
2025-04-21 06:26:21 +00:00
1. ** [Data ](#data )**: Used to pass data or query names to the component. These queries can be triggered from inside the component.
2. ** [Code ](#code )**: Used to write the React code for the **Custom Component** . ToolJet offers two built-in functions to interact with the component: [Update Data ](#update-data-function ) function and [Run Query ](#run-query-function ) function.
2024-11-10 22:27:25 +00:00
2025-04-21 06:26:21 +00:00
## Data
2024-11-10 22:27:25 +00:00
2025-04-21 06:26:21 +00:00
Data can be passed to a custom component using the **Data** field. The data should be structured as an object or an array of objects. Query name can also be passed through this field to trigger queries using the custom component.
2024-11-10 22:27:25 +00:00
2025-04-21 06:26:21 +00:00
< img className = "screenshot-full" src = "/img/widgets/custom-component/data.png" alt = "Custom Component Data Property" / >
2024-11-10 22:27:25 +00:00
2025-04-21 06:26:21 +00:00
#### Example:
```json
{{{
title: 'Hi! There',
buttonText: 'Update Title',
queryName: 'fetchData'
}}}
```
**OR**
2024-11-10 22:27:25 +00:00
```json
2025-04-21 06:26:21 +00:00
{{{
images: [
{ "url" : "https://reqres.in/img/faces/7-image.jpg", "title" : "Olivia"},
{ "url" : "https://reqres.in/img/faces/5-image.jpg", "title" : "Liam"},
{ "url" : "https://reqres.in/img/faces/3-image.jpg", "title" : "Sophia"}
]
2024-11-10 22:27:25 +00:00
}}}
```
2025-04-21 06:26:21 +00:00
### Passing Data Through Query
Data fetched from a query can also be passed to the **Custom Component** in the data object.
< img className = "screenshot-full" src = "/img/widgets/custom-component/query-data.png" alt = "Custom Component Data Property" / >
## Code
2024-11-10 22:27:25 +00:00
2025-04-21 06:26:21 +00:00
The React code for a **Custom Component** can be added in the **Code** field. You can interact with the application through the custom component using the following parameter and in-built functions.
2024-11-10 22:27:25 +00:00
2025-04-21 06:26:21 +00:00
### Data Parameter
2024-11-10 22:27:25 +00:00
2025-04-21 06:26:21 +00:00
To access the data passed through the [data ](#data ) field, define the `data` parameter to the *MyCustomComponent* funtion.
#### Example
2024-11-10 22:27:25 +00:00
```js
2025-04-21 06:26:21 +00:00
import React from 'https://cdn.skypack.dev/react';
import ReactDOM from 'https://cdn.skypack.dev/react-dom';
import { Button, Container } from 'https://cdn.skypack.dev/@material-ui/core';
const MyCustomComponent = ({data}) => (
< Container >
< p > Employee Name: < b > {data.name}< / b > < / p >
< p > Designation: < b > {data.designation}< / b > < / p >
< p > Department: < b > {data.department}< / b > < / p >
2024-11-10 22:27:25 +00:00
< / Container >
);
const ConnectedComponent = Tooljet.connectComponent(MyCustomComponent);
ReactDOM.render(< ConnectedComponent / > , document.body);
```
2025-04-21 06:26:21 +00:00
< img className = "screenshot-full" src = "/img/widgets/custom-component/data-prop.png" alt = "Custom Component Data Property" / >
2024-11-10 22:27:25 +00:00
2025-04-21 06:26:21 +00:00
### Update Data Function
2024-11-10 22:27:25 +00:00
2025-04-21 06:26:21 +00:00
To update the data in the data object, you can use the in-built `updateData` function.
2024-11-10 22:27:25 +00:00
2025-04-21 06:26:21 +00:00
#### Example
2024-11-10 22:27:25 +00:00
2025-04-21 06:26:21 +00:00
```js
import React from 'https://cdn.skypack.dev/react';
import ReactDOM from 'https://cdn.skypack.dev/react-dom';
import { Button, Container } from 'https://cdn.skypack.dev/@material-ui/core';
const MyCustomComponent = ({data, updateData}) => (
< Container >
< p > Employee Name: < b > {data.name}< / b > < / p >
< p > Status: < b > {data.status}< / b > < / p >
< Button
color="primary"
variant="outlined"
onClick={() => {updateData({status: 'Inactive'})}}
>
{data.button}
< / Button >
< / Container >
);
2024-11-10 22:27:25 +00:00
2025-04-21 06:26:21 +00:00
const ConnectedComponent = Tooljet.connectComponent(MyCustomComponent);
ReactDOM.render(< ConnectedComponent / > , document.body);
```
2024-11-10 22:27:25 +00:00
2025-04-21 06:26:21 +00:00
< img className = "screenshot-full" src = "/img/widgets/custom-component/update-data.png" alt = "Custom Component Data Property" / >
2024-11-10 22:27:25 +00:00
2025-04-21 06:26:21 +00:00
### Run Query Function
2024-11-10 22:27:25 +00:00
2025-04-21 06:26:21 +00:00
**Custom Component** in ToolJet can be used to trigger queries. You can specify the query name in the [data ](#data ) field. Use the in-built `runQuery` function to execute the query dynamically from within the **Custom Component** .
2024-11-10 22:27:25 +00:00
2025-04-21 06:26:21 +00:00
#### Example
2024-11-10 22:27:25 +00:00
2025-04-21 06:26:21 +00:00
```js
import React from "https://cdn.skypack.dev/react";
import ReactDOM from "https://cdn.skypack.dev/react-dom";
import { Button, Container } from "https://cdn.skypack.dev/@material-ui/core";
const MyCustomComponent = ({ data, runQuery }) => (
< Container >
< h1 > Employee Details< / h1 >
< p > Name: < b > {data.name}< / b > < / p >
< p > Designation: < b > {data.designation}< / b > < / p >
< p > Department: < b > {data.department}< / b > < / p >
< p > Address: < b > {data.address}< / b > < / p >
< Button
color="primary"
variant="contained"
onClick={() => {
runQuery(data.queryName);
}}
>
Fetch Contact Info
< / Button >
< / Container >
);
2024-11-10 22:27:25 +00:00
2025-04-21 06:26:21 +00:00
const ConnectedComponent = Tooljet.connectComponent(MyCustomComponent);
ReactDOM.render(< ConnectedComponent / > , document.body);
);
2024-11-10 22:27:25 +00:00
2025-04-21 06:26:21 +00:00
const ConnectedComponent = Tooljet.connectComponent(MyCustomComponent);
ReactDOM.render(< ConnectedComponent / > , document.body);
```
2024-11-10 22:27:25 +00:00
2025-04-21 06:26:21 +00:00
< img className = "screenshot-full" src = "/img/widgets/custom-component/run-query.png" alt = "Custom Component Run Query code" / >