Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #288 from navikt/dev
Browse files Browse the repository at this point in the history
Bytt ut use-async og use-fetch med Axios
  • Loading branch information
klaramargrethehelgemo authored Jun 1, 2022
2 parents a06920c + 0bd7556 commit 6e4b805
Show file tree
Hide file tree
Showing 18 changed files with 621 additions and 321 deletions.
238 changes: 179 additions & 59 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
"@navikt/ds-css-internal": "0.7.3",
"@navikt/ds-icons": "0.8.10",
"@navikt/ds-react": "0.17.21",
"@navikt/ds-react-internal": "0.12.22",
"@navikt/ds-react-internal": "0.13.6",
"@navikt/fnrvalidator": "^1.1.4",
"@navikt/frontendlogger": "^2.0.0",
"@navikt/navspa": "4.1.1",
"@nutgaard/use-async": "^2.3.1",
"@nutgaard/use-fetch": "^2.3.1",
"animated-scroll-to": "^2.2.0",
"axios": "^0.27.2",
"classnames": "^2.3.1",
"constate": "^3.1.0",
"craco-less": "1.20.0",
Expand Down
16 changes: 9 additions & 7 deletions src/components/feature-fetcher.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import React, { PropsWithChildren, useEffect } from 'react';
import { useFetchFeatureToggle } from '../rest/api';
import { isPending } from '@nutgaard/use-fetch';
import { AxiosResponse } from 'axios';
import { fetchFeatureToggle } from '../rest/api';
import { Laster } from './felles/fetch';
import { hasData } from '../rest/utils';
import { Features } from '../rest/datatyper/feature';

import { useAppStore } from '../stores/app-store';
import { isNotStartedOrPending, isResolved, usePromise } from '../utils/use-promise';

function FeatureFetcher(props: PropsWithChildren<any>) {
const fetchFeatures = useFetchFeatureToggle();
const fetchFeatures = usePromise<AxiosResponse<Features>>(() => fetchFeatureToggle());
const { setFeatures } = useAppStore();

useEffect(() => {
if (hasData(fetchFeatures)) {
setFeatures(fetchFeatures.data);
if (isResolved(fetchFeatures)) {
setFeatures(fetchFeatures.result.data);
}
}, [setFeatures, fetchFeatures]);

if (isPending(fetchFeatures)) {
if (isNotStartedOrPending(fetchFeatures)) {
return <Laster midtstilt={true} />;
}

Expand Down
Loading

0 comments on commit 6e4b805

Please sign in to comment.