> ## Documentation Index
> Fetch the complete documentation index at: https://docs.runmorph.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Morph.Provider

> The `Morph.Provider` component initializes the Morph SDK and provides configuration context throughout your application.

The `Morph.Provider` component is a crucial setup component that must wrap your application to enable Morph functionality. It:

* Initializes the Morph SDK with your configuration
* Provides configuration context to all Morph components
* Automatically handles environment variable detection
* Manages the Morph client instance lifecycle

## Installation

```bash theme={null}
yarn add @runmorph/atoms
```

## Environment Variables

The provider automatically detects your public key from the following environment variables (in order of precedence):

1. `MORPH_PUBLIC_KEY`
2. `NEXT_PUBLIC_MORPH_PUBLIC_KEY`
3. `VITE_MORPH_PUBLIC_KEY`
4. `REACT_APP_MORPH_PUBLIC_KEY`

## Usage

<CodeGroup>
  ```typescript Basic.tsx theme={null}
  "use client"
  import { Morph } from "@runmorph/atoms";

  function App({ children }) {
      return (
          <Morph.Provider>
              {children}
          </Morph.Provider>
      );
  }

  export default App;
  ```

  ```typescript WithExplicitConfig.tsx theme={null}
  "use client"
  import { Morph } from "@runmorph/atoms";

  function App({ children }) {
      return (
          <Morph.Provider config={{ publicKey: "pk_..." }}>
              {children}
          </Morph.Provider>
      );
  }

  export default App;
  ```

  ```typescript NextJsApp.tsx theme={null}
  // app/layout.tsx
  import { Morph } from "@runmorph/atoms";

  export default function RootLayout({ children }) {
      return (
          <html>
              <body>
                  <Morph.Provider>
                      {children}
                  </Morph.Provider>
              </body>
          </html>
      );
  }
  ```
</CodeGroup>

## Props

<ResponseField name="config" type="object">
  <Expandable title="properties">
    <ResponseField name="publicKey" type="string" required>
      Publishable API key
    </ResponseField>

    <ResponseField name="baseUrl" type="string">
      Custom Morph API base URL
    </ResponseField>
  </Expandable>
</ResponseField>

<ParamField path="children" type="ReactNode" required>
  The child components that will have access to the Morph context.
</ParamField>

## Best Practices

1. Place the `MorphProvider` as high as possible in your component tree
2. Use environment variables for public key management in development
3. Explicitly pass configuration in production environments
4. Implement error boundaries around the provider for graceful error handling

## Security Considerations

1. Never expose your private key through the provider
2. Use appropriate environment variable prefixes for your framework
3. Implement proper CSP policies for your deployment environment
4. Keep your public key secure and rotate if compromised
