Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a useFlags hook that enumerates all flags #79

Closed
damiangreen opened this issue Sep 23, 2022 · 2 comments · Fixed by #88
Closed

Create a useFlags hook that enumerates all flags #79

damiangreen opened this issue Sep 23, 2022 · 2 comments · Fixed by #88
Labels
enhancement New feature or request

Comments

@damiangreen
Copy link

Describe the feature request

Describe the feature request

We would like to report in the UI a dynamic list of all flags used
Currently we'd need to do something along the lines of

Background

const testEnabled= useFlag('rmm-test')
const test2Enabled= useFlag('rmm-test2)

const test3Enabled= useFlag('rmm-test3)

And im not sure its possibly to iterate through an array and dynamically make hooks.

Solution suggestions

whereas ideally it'd be good to return an array or record of key value pairs

const allFlags = useFlags() // {rmm-test1:true,...}

It appears

 const client = useUnleashClient()
  const a = client.getAllToggles()

does something similar so perhaps the hook can just call getAllToggles

Background

No response

Solution suggestions

No response

@damiangreen damiangreen added the enhancement New feature or request label Sep 23, 2022
@Tymek
Copy link
Member

Tymek commented Sep 26, 2022

For disabled toggles we will need Unleash/unleash-proxy#97

@nunogois nunogois moved this from New to Todo in Issues and PRs Oct 4, 2022
@elisechant
Copy link
Contributor

elisechant commented Oct 11, 2022

Yeah a convenience like this with any checks/types etc would be good:

import { useUnleashClient } from '@unleash/proxy-client-react';

export const useFlags = () => {
  const client = useUnleashClient();
  return {
    getFlags: () => client.getAllToggles(),
  };
};

Repository owner moved this from Todo to Done in Issues and PRs Oct 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants