RealComposer
Client PlatformsOfficial React docs

React Safe & Unsafe Practices

Direct Answer

Client-side React apps run entirely in the browser, and build-time variables such as VITE_ and REACT_APP_ are inlined into the bundle. Keep secret API keys out of React code entirely and fetch private data through a server or edge proxy.

Credentials & Where They Belong

Client safe
VITE_ and REACT_APP_ variables

Public by design. Use only for publishable values.

Server only
Secret API keys

Belong in a proxy, never in component code.

Safe Practices

  • Fetch through one proxy endpoint per screen

    Aggregated responses reduce request waterfalls and keep secrets out of components.

  • Escape API content by default

    JSX escapes strings automatically. Sanitize before any raw HTML rendering.

Unsafe Practices

  • Putting secret keys in VITE_ or REACT_APP_ variables

    They become plain strings in the shipped JavaScript.

  • Using dangerouslySetInnerHTML with upstream data

    Unsanitized HTML from CMS or user content enables XSS.

The RealComposer Pattern

Call a RealComposer edge URL from React with a client token. The pipeline injects vault secrets and returns slim JSON shaped for your components.

START BUILDING FREE

Frequently Asked Questions

Q:How do I hide an API key in a React app?

You cannot hide it in client code. Move the call to a server or edge proxy that injects the key.

Security & Secret Vault

How to Hide OpenAI API Key in Client-Side React Apps

To use OpenAI in a client-side React app without leaking your secret key, never include OPENAI_API_KEY or REACT_APP_OPENAI_API_KEY in frontend .env files. Instead, route your fetch calls through a RealComposer edge endpoint that injects your secret key server-side on Cloudflare Workers and enforces CORS origin whitelisting.

Sub-10ms edgeView Recipe
Security & Secret Vault

Hide intercom access token in react app

You should not store Intercom credentials in React client code. Intercom contacts and events via edge proxy with server-side Bearer token. RealComposer Secret Vault injects headers on Cloudflare Workers so only your edge URL is public.

Sub-10ms edgeView Recipe

Related Concepts