9.2.0 • Published 4 days ago

@kameleoon/react-sdk v9.2.0

Weekly downloads
-
License
ISC
Repository
-
Last release
4 days ago

Kameleoon React SDK

Introduction

Kameleoon React SDK is used to work with Kameleoon Feature Flags and Experiments using native JavaScript or specific React Native APIs. The package provides a number of hooks and wrappers that can grant React oriented support for Kameleoon SDK when using it in React or React Native applications.

This page describes the most basic configuration, for more in-depth review of all the hooks and configuration options follow Official Kameleoon Documentation

Contents

Installation

  • npm - npm install @kameleoon/react-sdk
  • yarn - yarn add @kameleoon/react-sdk
  • pnpm - pnpm add @kameleoon/react-sdk
  • bun - bun install @kameleoon/react-sdk

Configuration

  1. Obtain your site code from Kameleoon Platform
  2. Instantiate SDK client and pass it to KameleoonProvider
import { KameleoonProvider, createClient } from '@kameleoon/react-sdk';

const client = createClient({ siteCode: 'my_site_code' });

function MyComponentWrapper(): JSX.Element {
  return (
    <KameleoonProvider client={client}>
      <MyComponent />
    </KameleoonProvider>
  );
}

Usage Example

import { useEffect } from 'react';
import {
  useData,
  CustomData,
  useInitialize,
  useVisitorCode,
  useFeatureFlag,
} from '@kameleoon/react-sdk';

function MyComponent(): JSX.Element {
  const { initialize } = useInitialize();
  const { addData } = useData();
  const { isFeatureFlagActive } = useFeatureFlag();
  const { getVisitorCode } = useVisitorCode();

  async function init(): Promise<void> {
    // -- Wait for the client initialization
    await initialize();

    // -- Generate a visitor code
    const visitorCode = getVisitorCode();

    // -- Add targeting data
    const customDataIndex = 0;
    addData(visitorCode, new CustomData(customDataIndex, 'my_data'));

    // -- Check if the feature is active for visitor
    const isActive = isFeatureFlagActive(visitorCode, 'my_feature_key');
  }

  useEffect(() => {
    init();
  }, []);
}
9.2.0

4 days ago

9.1.0

19 days ago

9.0.1

3 months ago

9.0.0

3 months ago

8.5.2

3 months ago

8.5.1

3 months ago

8.5.0

4 months ago

8.4.1

5 months ago

8.4.0

5 months ago

8.3.0

5 months ago

8.2.1

5 months ago

7.4.0

10 months ago

7.3.1

11 months ago

7.5.3

8 months ago

7.6.1

7 months ago

7.5.2

8 months ago

7.6.0

7 months ago

7.5.1

9 months ago

7.5.0

9 months ago

7.4.1

10 months ago

7.3.2

10 months ago

7.5.4

7 months ago

8.1.0

6 months ago

8.0.0

6 months ago

8.2.0

5 months ago

7.3.0

11 months ago

7.2.2

12 months ago

7.2.1

12 months ago

7.2.0

12 months ago

7.2.4

11 months ago

7.2.3

12 months ago

6.1.0

1 year ago

6.0.0

1 year ago

6.1.2

1 year ago

6.1.1

1 year ago

6.1.3

1 year ago

7.0.0

1 year ago

7.1.2

1 year ago

7.1.1

1 year ago

7.1.0

1 year ago

5.0.0

1 year ago

4.1.0

2 years ago

4.1.1

2 years ago

4.0.1

2 years ago

4.0.3

2 years ago

4.0.2

2 years ago

4.0.0

2 years ago

3.0.0

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago