Skip to content

2.0.0 - react hook support for React+React Native

Choose a tag to compare

@kyle-ssg kyle-ssg released this 22 Mar 11:23
· 482 commits to main since this release

React and React Native users will now be able to use a hook based approach to retrieving flags

import React from 'react';
import flagsmith from 'flagsmith' // 'react-native-flagsmith';  for react-native
import {FlagsmithProvider} from 'flagsmith/react';
import AppComponent from './ExampleComponent';


export default function () {
  return (
    <FlagsmithProvider
      options={{
        environmentID: 'QjgYur4LQTwe5HpvbvhpzK',
      }}
      flagsmith={flagsmith}>
      <AppComponent />
    </FlagsmithProvider>
  );
}

Then in your app

  const flags = useFlags(['font_size'], ['example_trait']); // only causes re-render if specified flag values / traits change
   ...
   <div>font_size: {flags.font_size?.value}</div>