## Basic Initialization

The first step to using Instant in your app is to call `init`. Here is a simple example at the root of your app.

```javascript
import { init } from '@instantdb/react';

// Visit https://instantdb.com/dash to get your APP_ID :)
const APP_ID = '__APP_ID__';

const db = init({ appId: APP_ID });

function App() {
  return <Main />;
}
```

With that, you can use `db` to [write data](/content/docs/instaml/index.html), [make queries](/content/docs/instaql/index.html), [handle auth](/content/docs/auth/index.html), and more!

## Typesafety

If you're using typescript, `init` accepts a `schema` argument. Adding a schema provides auto-completion and typesafety for your queries and transactions.

```typescript
import { init, i } from '@instantdb/react';

// Visit https://instantdb.com/dash to get your APP_ID :)
const APP_ID = '__APP_ID__';

const schema = i.schema({
  entities: {
    $files: i.entity({
      path: i.string().unique().indexed(),
      url: i.any(),
    }),
    $users: i.entity({
      email: i.string().unique().indexed(),
    }),
    todos: i.entity({
      text: i.string(),
      done: i.boolean(),
      createdAt: i.number(),
    }),
  },
});

const db = init({ appId: APP_ID, schema });
```

To learn more about writing schemas, head on over to the [Modeling your data](/content/docs/modeling-data/index.html) section.

## Flexible Initialization

Instant maintains a single connection regardless of where or how many times you call `init` with the same app ID. This means you can safely call `init` multiple times without worrying about creating multiple connections or performance overhead. However, we do recommend the pattern of exporting a reference from a utility file like so:

```typescript
// lib/db.ts
import { init } from '@instantdb/react';
import schema from '../instant.schema';

// Visit https://instantdb.com/dash to get your APP_ID :)
const APP_ID = '__APP_ID__';
export const db = init({ appId: APP_ID, schema });

// app/page.tsx
"use client";

import { db } from '../lib/db';

function App() {
  // do some instant magic 🪄
  db.useQuery({ todos: {} });
}

export default App;
```

## Configuration Options

`init` accepts a few options. For most use cases you'll want to provide `appId` and `schema`. Here are all the options you can provide:

- **appId** (required): Your InstantDB application ID. This identifies your app and is used to connect to the correct backend.
- **schema?**: Instant schema export from your `instant.schema.ts` file. Provide this for typesafety and auto-completion in queries, transactions, and ephemeral features.
- **websocketURI?**: Custom WebSocket endpoint for real-time connections. Defaults to `'wss://api.instantdb.com/runtime/session'`. Change this for connecting to development or self-hosted instances.
- **apiURI?**: Custom HTTP API endpoint for auth and storage operations. Defaults to `'https://api.instantdb.com'`. Change this for connecting to development or self-hosted instances.
- **devtool?**: Controls the Instant dev tool. Defaults to `true` on localhost. Set to `false` to disable, or configure with `{ position: 'bottom-right', allowedHosts: ['localhost'] }`.
- **verbose?**: Enables detailed console logging for debugging. When `true`, logs WebSocket messages and internal operations. Helpful for troubleshooting connection and sync issues.
- **queryCacheLimit?**: Maximum number of query subscriptions to cache for offline mode. Defaults to `10`. Cached queries provide instant data on app reload while fresh data loads in the background.
- **useDateObjects?**: When `true`, all date columns in queries will return a Javascript `Date` object. Disabled by default.

If you are an LLM trying to learn how to develop with Instant, here are all of the links to the docs:

[Getting started w/ React](/content/docs/index.html)  
[Getting started w/ React Native](/content/docs/start-rn/index.html)  
[Getting started w/ Vanilla JS](/content/docs/start-vanilla/index.html)  
[Getting started w/ SolidJS](/content/docs/start-solidjs/index.html)  
[Getting started w/ Svelte](/content/docs/start-svelte/index.html)  
[Getting started w/ TanStack Start](/content/docs/start-tanstack/index.html)  
[Create Instant App](/content/docs/create-instant-app/index.html)  
[Recommended Workflow](/content/docs/workflow/index.html)  
[Using LLMs](/content/docs/using-llms/index.html)  
[Init](/content/docs/init/index.html)  
[Modeling data](/content/docs/modeling-data/index.html)  
[Writing data](/content/docs/instaml/index.html)  
[Reading data](/content/docs/instaql/index.html)  
[Infinite Queries](/content/docs/infinite-queries/index.html)  
[Instant on the backend](/content/docs/backend/index.html)  
[Patterns](/content/docs/patterns/index.html)  
[Auth](/content/docs/auth/index.html)  
[Magic codes](/content/docs/auth/magic-codes/index.html)  
[Guest Auth](/content/docs/auth/guest-auth/index.html)  
[Google OAuth](/content/docs/auth/google-oauth/index.html)  
[Sign In with Apple](/content/docs/auth/apple/index.html)  
[GitHub OAuth](/content/docs/auth/github-oauth/index.html)  
[LinkedIn OAuth](/content/docs/auth/linkedin-oauth/index.html)  
[Clerk](/content/docs/auth/clerk/index.html)  
[Firebase Auth](/content/docs/auth/firebase/index.html)  
[Permissions](/content/docs/permissions/index.html)  
[Rate Limits](/content/docs/rate-limits/index.html)  
[Managing users](/content/docs/users/index.html)  
[Presence, Cursors, and Activity](/content/docs/presence-and-topics/index.html)  
[Instant CLI](/content/docs/cli/index.html)  
[Devtool](/content/docs/devtool/index.html)  
[Platform API](/content/docs/platform-api/index.html)  
[Explorer Component](/content/docs/explorer-component/index.html)  
[Custom emails](/content/docs/emails/index.html)  
[App teams](/content/docs/teams/index.html)  
[Storage](/content/docs/storage/index.html)  
[Streams](/content/docs/streams/index.html)  
[Stripe Payments](/content/docs/stripe-payments/index.html)  
[Admin HTTP API](/content/docs/http-api/index.html)  
[(Experimental) Next.js SSR](/content/docs/next-ssr/index.html)  
[Migrating from Supabase](/content/docs/migrate-from-supabase/index.html)
