---
url: >-
  https://game-engine-io.github.io/enginex-frontend-sdk/reference/api/@getenginex/sdk-react/functions/EnginexProvider.md
---
[Reference](../../../index.md) / [@getenginex/sdk-react](../index.md) / EnginexProvider

# EnginexProvider()

> **EnginexProvider**(`__namedParameters`): `ReactNode`

Connects the SDK client and TanStack Query to the React tree: exposes the client to `useEnginex` and `useSession`
and renders a `QueryClientProvider` (with the given `queryClient` or one of its own, created only
once per provider instance, with a `staleTime` of 60 s on queries).

When the session user changes (logout, login, or login with a different `sub`), it removes from the cache (not just
invalidates) everything under `['enginex', 'user']`, so one player's data is never served to another.
The comparison uses `status` and `userId`: an authenticated session without `sub` (opaque token) differs from the
anonymous one. Renewing the same user's tokens clears nothing. The `['enginex', 'public']` queries and the
app's keys stay untouched.

`client` and `queryClient` must be stable. If `client` changes while the provider is mounted, the tree
starts using the new client, the session subscription moves to it and the user cache is cleared only if
the user (or the status) differs from the last one seen; the rest of the cache (including `public`, which may
belong to another tenant) is left as is. To switch tenant, remount the provider with a `key`.

## Parameters

### \_\_namedParameters

[`EnginexProviderProps`](../interfaces/EnginexProviderProps.md)

## Returns

`ReactNode`

## Example

```ts
const enginex = createEnginexClient({ locale: 'pt-BR' })

export function App() {
  return (
    <EnginexProvider client={enginex}>
      <Home />
    </EnginexProvider>
  )
}
```
