-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from Optum/useLoadData-changes
Use load data changes
- Loading branch information
Showing
82 changed files
with
1,367 additions
and
96 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+21.7 KB
.yarn/cache/@babel-helper-compilation-targets-npm-7.23.6-aa6f07f088-c630b98d45.zip
Binary file not shown.
Binary file added
BIN
+4.31 KB
.yarn/cache/@babel-helper-environment-visitor-npm-7.22.20-260909e014-d80ee98ff6.zip
Binary file not shown.
Binary file added
BIN
+8.77 KB
.yarn/cache/@babel-helper-function-name-npm-7.23.0-ce38271242-e44542257b.zip
Binary file not shown.
Binary file added
BIN
+4.5 KB
.yarn/cache/@babel-helper-hoist-variables-npm-7.22.5-6db3192347-394ca191b4.zip
Binary file not shown.
Binary file added
BIN
+16 KB
.yarn/cache/@babel-helper-module-imports-npm-7.22.15-687e77ee50-ecd7e457df.zip
Binary file not shown.
Binary file added
BIN
+45.4 KB
.yarn/cache/@babel-helper-module-transforms-npm-7.23.3-69078a931c-5d0895cfba.zip
Binary file not shown.
Binary file added
BIN
+6.18 KB
.yarn/cache/@babel-helper-plugin-utils-npm-7.22.5-192e38e1de-c0fc722707.zip
Binary file not shown.
Binary file added
BIN
+5.9 KB
.yarn/cache/@babel-helper-simple-access-npm-7.22.5-0a3f578780-fe9686714c.zip
Binary file not shown.
Binary file added
BIN
+5.25 KB
.yarn/cache/@babel-helper-split-export-declaration-npm-7.22.6-e723505aef-e141cace58.zip
Binary file not shown.
Binary file added
BIN
+9.82 KB
.yarn/cache/@babel-helper-string-parser-npm-7.23.4-b1f0d030c3-c0641144cf.zip
Binary file not shown.
Binary file added
BIN
+17.5 KB
.yarn/cache/@babel-helper-validator-identifier-npm-7.22.20-18305bb306-136412784d.zip
Binary file not shown.
Binary file added
BIN
+7.16 KB
.yarn/cache/@babel-helper-validator-option-npm-7.23.5-d83bbfe738-537cde2330.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+3.56 KB
.yarn/cache/@babel-plugin-syntax-jsx-npm-7.23.3-9ff8fd9153-8903769431.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+17.9 KB
.yarn/cache/@jridgewell-resolve-uri-npm-3.1.1-aa2de3f210-f5b441fe79.zip
Binary file not shown.
Binary file added
BIN
+44.3 KB
.yarn/cache/@jridgewell-trace-mapping-npm-0.3.22-0baba2f798-ac7dd2cfe0.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+19.3 KB
.yarn/cache/@sinonjs-fake-timers-npm-10.3.0-7417f876b4-614d30cb4d.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+6.57 KB
.yarn/cache/update-browserslist-db-npm-1.0.13-ea7b8ee24d-1e47d80182.zip
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './useLoadData' | ||
export * from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {Promisable} from '../../types'; | ||
|
||
import {UnboxApiResponse} from './UnboxApiResponse'; | ||
import {NotUndefined} from './NotUndefined'; | ||
|
||
export type FetchData<T extends NotUndefined, Deps extends any[]> = ( | ||
...args: readonly [...UnboxApiResponse<Deps>] | ||
) => Promisable<T>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
export type NotUndefined = {} | null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import {ApiResponseBase} from '../../types'; | ||
|
||
export type UnboxApiResponse<F extends any[]> = { | ||
[P in keyof F]: F[P] extends ApiResponseBase<any> ? Exclude<F[P]['result'], undefined> : F[P]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './NotUndefined'; | ||
export * from './UnboxApiResponse'; | ||
export * from './FetchData'; |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# `useOptionalDependecy` | ||
|
||
A React hook that safely optionalizes retry responses. | ||
|
||
## Usage | ||
`useOptionalDependency` is designed to be used in tandem with [useLoadData](../useLoadData/). This hook will safely optionalize a [retry response objects](../../RetryResponse.ts), meaning an optional dependency that returns type `T` will be typed as `T | null` when passed into `fetchData`, and will always be treated as _null_ by `useLoadData` if the dependency errors. The advantage here being that `useLoadData` will still wait upon the optional dependency to resolve (successfully or unsucessfully), and more significantly, does not hold up a dependency chain while still exposing an error. | ||
|
||
```Typescript | ||
import React from 'react'; | ||
import {useLoadData} from '@Optum/react-hooks'; | ||
|
||
export const MyComponent = (props) => { | ||
const loadedUserProfile = useLoadData(fetchUserProfile); // loadedUserProfile will be of type RetryResponse<Profile> | ||
|
||
const optionalizedUserProfile = useOptionalDependency(loadedUserProfile); | ||
const loadedResults = useLoadData( | ||
async (userProfile) => { // userProfile will be of type Profile | null due to being optionalized | ||
if(!userProfile) { | ||
return fetchResultsWithoutProfile() | ||
} else { | ||
return fetchResults(userProfile) | ||
} | ||
}, | ||
[optionalizedUserProfile] | ||
); | ||
|
||
} | ||
``` | ||
|
||
## API | ||
|
||
`useOptionalDependency` takes the following arguments: | ||
|
||
| Name | Type | Description | | ||
|-|-|-| | ||
| `dependency` | `RetryResponse<T>` | return value from `useLoadData` to be optionalized | | ||
|
||
|
||
The return value of `useOptionalDependency` is `OptionalDependency<T>`, where `T` is the type of the result. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './useOptionalDependency'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import {useMemo} from 'react'; | ||
import {ApiResponse, OptionalDependency} from '../../types'; | ||
|
||
export function useOptionalDependency<T>(dep: ApiResponse<T>): OptionalDependency<T> { | ||
return useMemo(() => ({...dep, optional: true}), [dep]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.