Reference

Interfaces

CheckEvent

Event representing checking the flag evaluation result

Properties

Property
Type
Description

action

"check-is-enabled" | "check-config"

check-is-enabled means isEnabled was checked, check-config means config was checked.

key

string

Flag key.

missingContextFields?

string[]

Missing context fields.

ruleEvaluationResults?

boolean[]

Rule evaluation results.

value?

| boolean | { key: string; payload: any; }

Result of flag or configuration evaluation. If action is check-is-enabled, this is the result of the flag evaluation and value is a boolean. If action is check-config, this is the result of the configuration evaluation.

version?

number

Version of targeting rules.


CompanyContext

Context is a set of key-value pairs. This is used to determine if feature targeting matches and to track events. Id should always be present so that it can be referenced to an existing company.

Indexable

[key: string]: undefined | string | number

Properties

Property
Type
Description

id

undefined | string | number

Company id

name?

string

Company name


Flag<TConfig>

Describes a feature

Type Parameters

Type Parameter
Default type

TConfig extends FlagType["config"]

Properties

Property
Type
Description

config

| EmptyFlagRemoteConfig | { key: string; } & TConfig

isEnabled

boolean

If the feature is enabled.

isLoading

boolean

If the feature is loading.

key

string

The key of the feature.

requestFeedback

(opts: RequestFeedbackOptions) => void

Request feedback from the user.

Methods

track()

Track feature usage in Reflag.

Returns

| undefined | Promisearrow-up-right< | undefined | Responsearrow-up-right>


Flags


UserContext

Context is a set of key-value pairs. This is used to determine if feature targeting matches and to track events. Id should always be present so that it can be referenced to an existing user.

Indexable

Properties

Property
Type
Description

email?

string

User email

id

undefined | string | number

User id

name?

string

User name

Type Aliases

BootstrappedFlags

Type declaration

Name
Type

EmptyFlagRemoteConfig

Type declaration

Name
Type

key

undefined

payload

undefined


FlagKey


FlagRemoteConfig

A remotely managed configuration value for a feature.

Type declaration

{ key: string; payload: any; }

Name
Type
Description

key

string

The key of the matched configuration value.

payload

any

The optional user-supplied payload data.

EmptyFlagRemoteConfig


FlagType

Type declaration

Name
Type

config?

{ payload: any; }

config.payload

any


RawFlags

Describes a collection of evaluated raw flags.


ReflagBootstrappedProps

Props for the ReflagBootstrappedProvider.

Type declaration

Name
Type
Description

flags

Pre-fetched flags to be used instead of fetching them from the server.


ReflagClientProviderProps

Props for the ReflagClientProvider.

Type declaration

Name
Type

ReflagInitOptionsBase

Internal

Base init options for the ReflagProvider and ReflagBootstrappedProvider.


ReflagProps

Props for the ReflagProvider.

Type declaration

Name
Type
Description

company?

Company related context. If you provide id Reflag will enrich the evaluation context with company attributes on Reflag servers.

Deprecated

Use context instead, this property will be removed in the next major version

context?

The context to use for the ReflagClient containing user, company, and other context.

otherContext?

Recordarrow-up-right<string, string | number | undefined>

Context which is not related to a user or a company.

Deprecated

Use context instead, this property will be removed in the next major version

user?

User related context. If you provide id Reflag will enrich the evaluation context with user attributes on Reflag servers.

Deprecated

Use context instead, this property will be removed in the next major version


ReflagPropsBase

Internal

Base props for the ReflagProvider and ReflagBootstrappedProvider.

Type declaration

Name
Type
Description

children?

ReactNode

The children to render after the client is initialized.

debug?

boolean

Set to true to enable debug logging to the console,

initialLoading?

boolean

Set to true to show the loading component while the client is initializing.

loadingComponent?

ReactNode

A React component to show while the client is initializing.


RequestFeedbackOptions


TrackEvent

Type declaration

Name
Type

attributes?

| Recordarrow-up-right<string, any> | null

eventName

string


TypedFlags

Describes a collection of evaluated feature.

Remarks

This types falls back to a generic Record<string, Flag> if the Flags interface has not been extended.

Functions

ReflagBootstrappedProvider()

Bootstrapped Provider for the ReflagClient using pre-fetched flags.

Parameters

Parameter
Type

__namedParameters

Returns

Element


ReflagClientProvider()

Parameters

Parameter
Type

__namedParameters

Returns

Element


ReflagProvider()

Provider for the ReflagClient.

Parameters

Parameter
Type

__namedParameters

Returns

Element


useClient()

Returns the current ReflagClient used by the ReflagProvider.

This is useful if you need to access the ReflagClient outside of the ReflagProvider.

Returns

ReflagClient

The ReflagClient.

Example


useFeature()

Type Parameters

Type Parameter

TKey extends string

Parameters

Parameter
Type

key

TKey

Returns

Flag

Deprecated

use useFlag instead


useFlag()

Returns the state of a given feature for the current context, e.g.

Type Parameters

Type Parameter

TKey extends string

Parameters

Parameter
Type

key

TKey

Returns

TypedFlags[TKey]


useIsLoading()

Returns a boolean indicating if the Reflag client is loading. You can use this to check if the Reflag client is loading at any point in your application. Initially, the value will be true until the client is initialized.

Returns

boolean

A boolean indicating if the Reflag client is loading.

Example


useOnEvent()

Attach a callback handler to client events to act on changes. It automatically disposes itself on unmount.

Type Parameters

Type Parameter

THookType extends keyof HookArgs

Parameters

Parameter
Type
Description

event

THookType

The event to listen to.

handler

(arg0: HookArgs[THookType]) => void

The function to call when the event is triggered.

client?

The Reflag client to listen to. If not provided, the client will be retrieved from the context.

Returns

void

Example


useRequestFeedback()

Returns a function to open up the feedback form Note: When calling useRequestFeedback, user/company must already be set.

See link for more information

Returns

Function

Parameters

Parameter
Type

Returns

void


useSendFeedback()

Returns a function to manually send feedback collected from a user. Note: When calling useSendFeedback, user/company must already be set.

See link for more information

Returns

Function

Parameters

Parameter
Type

Returns

Promisearrow-up-right< | undefined | Responsearrow-up-right>


useTrack()

Returns a function to send an event when a user performs an action Note: When calling useTrack, user/company must already be set.

Returns

Function

Parameters

Parameter
Type

eventName

string

attributes?

| null | Recordarrow-up-right<string, any>

Returns

Promisearrow-up-right< | undefined | Responsearrow-up-right>


useUpdateCompany()

Returns a function to update the current company's information. For example, if the company changed plan or opted into a beta-feature.

The method returned is a function which returns a promise that resolves when after the features have been updated as a result of the company update.

Returns

Function

Parameters

Parameter
Type

opts

{}

Returns

Promisearrow-up-right<void>


useUpdateOtherContext()

Returns a function to update the "other" context information. For example, if the user changed workspace, you can set the workspace id here.

The method returned is a function which returns a promise that resolves when after the features have been updated as a result of the update to the "other" context.

Returns

Function

Parameters

Parameter
Type

opts

{}

Returns

Promisearrow-up-right<void>


useUpdateUser()

Returns a function to update the current user's information. For example, if the user changed role or opted into a beta-feature.

The method returned is a function which returns a promise that resolves when after the features have been updated as a result of the user update.

Returns

Function

Parameters

Parameter
Type

opts

{}

Returns

Promisearrow-up-right<void>

Last updated

Was this helpful?