Search code examples
javascriptreactjsunleash

is there a way to get all flags from Unleash in react?


I'm using @unleash/proxy-client-react package I know that we can get specific flag from unleash by "useVariant" or "useFlag". is there a way that we can get all flags at the same time from unleash or have access to unleash api response?


Solution

  • You can use the useFlags hook. This will return an array with all flags:

    import { useFlags } from '@unleash/proxy-client-react';
    
    const Component = () => {
      const flags = useFlags();
      console.log(flags) // Returns all flags
      ...
    }
    
    

    It doesn't seem to be in the docs, but you can find the hook in the source code.