Docs
/
/
In-App UI
React
Components
KnockProvider

KnockProvider

A React context provider that initializes and provides the Knock client instance to child components throughout your application.

Usage

#

Props

#
apiKeystringRequired

Your public API key from the Knock dashboard.

userobject

A user object containing information to identify the user on Knock.

identificationStrategystring

Defaults to inline. Can be set to skip to skip inline identification.

userTokenstring

The JWT token for authenticating the user (required when using enhanced security mode).

enabledboolean

Defaults to true. When false, children still render but the Knock client stays idle: no identify call, no API requests, and no websocket. Flipping it to true authenticates and connects the client; flipping it back to false disconnects it and clears its data. Use it to defer activity until you have a complete identity (see below).

hoststring

The Knock API host URL. Defaults to the production Knock API.

logLevelstring

When set to debug, will output additional logging to aid with debugging.

childrenReactNode

Child components that will have access to the Knock client.

Deferring activity with enabled

#

KnockProvider takes an enabled prop that defaults to true. When it's false, the provider still renders its children, but the Knock client sits idle: it doesn't identify the user, make any API requests, or open a websocket. Set it back to true and the client authenticates and connects; set it to false again and it disconnects and clears its data.

This is the recommended way to gate the provider on a complete identity — for example, an enhanced-security user token that isn't ready on the first render — rather than mounting and unmounting KnockProvider as that identity changes:

Reach for enabled whenever you render the provider before authentication or consent is ready, such as feature-flagged rollouts, gated workspaces, or cookie consent flows.

Behavior when enabled changes

#
  • Feed components remount and reload their data when enabled becomes true.
  • Slack and Microsoft Teams connection status re-checks when the authenticated user changes.
  • Guides begin targeting once the client is authenticated. The enabled prop gates the whole client, while the readyToTarget prop on KnockGuideProvider gates guide targeting on its own.

To react to these transitions in your own components, subscribe to the client's authentication state with the useKnockAuthState hook.

New chat