> For the complete documentation index, see [llms.txt](https://docs.jamaibase.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.jamaibase.com/developer-reference/framework-integration/reactjs.md).

# ReactJS

## 1. Setup JamAIBase project.

* Create a new project.

<figure><img src="https://949944545-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRNnvWSkFcg9eUeFklENf%2Fuploads%2Fcb6CxaTjAbzhEQWqvs1Y%2Fimage.png?alt=media&amp;token=53d96b1e-f942-4c6b-8614-9b5708b0f238" alt=""><figcaption></figcaption></figure>

* Get the **Project ID**.

<figure><img src="https://949944545-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRNnvWSkFcg9eUeFklENf%2Fuploads%2FYUP5b640Ay6rWcQakEOt%2Fimage.png?alt=media&amp;token=0e40cd24-0756-4734-b0fd-27f498aa9d2c" alt=""><figcaption></figcaption></figure>

* Create **JamAI API Key** at **Organization > Secrets > Create API Key.**

<figure><img src="https://949944545-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRNnvWSkFcg9eUeFklENf%2Fuploads%2FiKEvdvKwhs9LsLPImRxc%2FWhatsApp%20Image%202024-05-30%20at%2020.54.27.jpeg?alt=media&amp;token=aa43f907-abda-425a-81b8-93aa18c2004d" alt=""><figcaption></figcaption></figure>

### 2. Install React and Create a New Project

```
npx create-react-app my-app
cd my-app
```

## 3. Install jamaibase.

```
npm install jamaibase
```

## 4. Create and Use the JamAI Client in your React component

Note: Exposing your API key directly in the client-side code is a security risk. For improved security, consider using a framework like Next.js or SvelteKit that allows server-side rendering.

```tsx
// App.tsx

import { useEffect, useState } from "react";
import JamAI from "jamaibase";
import { PageListTableMetaResponse } from "jamaibase/resources/gen_tables/tables";

export default function Home() {
    const [tableData, setTableData] = useState<PageListTableMetaResponse>();

    useEffect(() => {
        const fetchData = async () => {
            const jamai = new JamAI({
                baseURL: process.env.NEXT_PUBLIC_JAMAI_BASEURL!,
                apiKey: process.env.JAMAI_API_KEY,
                projectId: process.env.JAMAI_PROJECT_ID,
            });
            try {
                const response = await jamai.listTables({
                    table_type: "action",
                });
                setTableData(response);
            } catch (err: any) {
                console.error(err.message);
            }
            fetchData();
        };
    }, []);

    return (
        <div>
            <h1>List of Tables</h1>
            <ul>
                {tableData?.items.map((table) => (
                    <li key={table.id}>
                        <h2>Table ID: {table.id}</h2>
                        <h3>Columns:</h3>
                        <ul>
                            {table.cols.map((column) => (
                                <li key={column.id}>
                                    <p>ID: {column.id}</p>
                                    <p>Data Type: {column.dtype}</p>
                                    {/* Render other properties as needed */}
                                </li>
                            ))}
                        </ul>
                    </li>
                ))}
            </ul>
        </div>
    );
}
```

## 5. Start the app

```
npm run dev
```


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.jamaibase.com/developer-reference/framework-integration/reactjs.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
