KnockProvider
A React context provider that initializes and provides the Knock client instance to child components throughout your application.
Usage
#Props
#Your public API key from the Knock dashboard.
A user object containing information to identify the user on Knock.
Defaults to inline. Can be set to skip to skip inline identification.
The JWT token for authenticating the user (required when using enhanced security mode).
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).
The Knock API host URL. Defaults to the production Knock API.
When set to debug, will output additional logging to aid with debugging.
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
enabledbecomestrue. - Slack and Microsoft Teams connection status re-checks when the authenticated user changes.
- Guides begin targeting once the client is authenticated. The
enabledprop gates the whole client, while thereadyToTargetprop onKnockGuideProvidergates 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.