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

Flytter useFeaturetoggles til v2 #6934

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Conversation

hallvardastark
Copy link
Collaborator

Skriver litt om slik at den bruker react-query fremfor gammel rigg

Skriver litt om slik at den bruker react-query fremfor gammel rigg
@hallvardastark hallvardastark requested a review from a team as a code owner December 16, 2024 11:33
@@ -53,9 +46,13 @@ const AppConfigResolver = ({ children }: OwnProps) => {
harHentetFerdigKodeverk &&
navAnsattState === RestApiState.SUCCESS &&
sprakFilState === RestApiState.SUCCESS &&
(featureToggleState === RestApiState.NOT_STARTED || featureToggleState === RestApiState.SUCCESS);
!!featureToggles;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useFeatureToggles() ser for meg ut til å returnere eit tomt objekt før respons er henta. Det betyr vel at !!featureToggles blir true før featureToggles faktisk har blitt satt? Dermed kan rendering av children potensielt starte med tomt featureToggles objekt for deretter å bli re-rendra?

Ville det vere betre om useFeatureToggles returnerte objekt med featureToggles prop som er undefined før det er henta, istadenfor array?

const transformData = (data: FeatureToggle[]): FeatureToggles =>
  data?.reduce((acc: { [x: string]: boolean }, curr: FeatureToggle) => {
    acc[curr.key] = `${curr.value}`.toLowerCase() === 'true';
    return acc;
  }, {});

export const useFeatureToggles = (): {featureToggles: FeatureToggles | undefined} => {
  const backendUrl = window.location.pathname.includes('/ung/web') ? 'ung' : 'k9';
  const { data: featureToggles } = useQuery({
    queryKey: ['featureToggles'],
    queryFn: ({ signal }) =>
      axios.get(`/${backendUrl}/feature-toggle/toggles.json`, { signal }).then(({ data }) => data),
    select: transformData,
  });

  return {featureToggles}
};

Og så i her i AppConfigResolver:

const {featureToggles} = useFeatureToggles();

Då ville vel erFerdig bli satt meir korrekt trur eg.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants