-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: master
Are you sure you want to change the base?
Conversation
Skriver litt om slik at den bruker react-query fremfor gammel rigg
Bruker ikke gammel rigg for dette mer
@@ -53,9 +46,13 @@ const AppConfigResolver = ({ children }: OwnProps) => { | |||
harHentetFerdigKodeverk && | |||
navAnsattState === RestApiState.SUCCESS && | |||
sprakFilState === RestApiState.SUCCESS && | |||
(featureToggleState === RestApiState.NOT_STARTED || featureToggleState === RestApiState.SUCCESS); | |||
!!featureToggles; |
There was a problem hiding this comment.
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.
Skriver litt om slik at den bruker react-query fremfor gammel rigg