-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(react-core): ensure useDataState returns value of last dispatch (…
…#6382) * Create nasty-lemons-agree.md
- Loading branch information
1 parent
4a4d8d6
commit e6248bd
Showing
15 changed files
with
273 additions
and
58 deletions.
There are no files selected for viewing
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 @@ | ||
--- | ||
"@aws-amplify/ui-react-core": patch | ||
"@aws-amplify/ui-react-storage": patch | ||
--- | ||
|
||
chore(react-core): ensure useDataState returns value of last dispatch |
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,5 +1,5 @@ | ||
export { | ||
default as useDataState, | ||
useDataState, | ||
AsyncDataAction, | ||
DataAction, | ||
DataState, | ||
|
12 changes: 12 additions & 0 deletions
12
packages/react-core/src/hooks/useDataState/__tests__/useDataState.native.spec.ts
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,12 @@ | ||
import { renderHook } from '@testing-library/react'; | ||
|
||
import useDataState from '../useDataState.native'; | ||
|
||
it('throws the expected error when called with a type not mapped to an action handler', () => { | ||
// turn off console.error logging for unhappy path test case | ||
jest.spyOn(console, 'error').mockImplementation(() => {}); | ||
|
||
expect(() => renderHook(() => useDataState())).toThrow( | ||
new Error('useDataState is not implemented for React Native') | ||
); | ||
}); |
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,2 @@ | ||
export { default as useDataState } from './useDataState'; | ||
export { AsyncDataAction, DataAction, DataState } 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,13 @@ | ||
export interface DataState<T> { | ||
data: T; | ||
hasError: boolean; | ||
isLoading: boolean; | ||
message: string | undefined; | ||
} | ||
|
||
export type DataAction<T = any, K = any> = (prevData: T, input: K) => T; | ||
|
||
export type AsyncDataAction<T = any, K = any> = ( | ||
prevData: T, | ||
input: K | ||
) => Promise<T>; |
3 changes: 3 additions & 0 deletions
3
packages/react-core/src/hooks/useDataState/useDataState.native.ts
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 default function useDataState(): void { | ||
throw new Error('useDataState is not implemented for React Native'); | ||
} |
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
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
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
7 changes: 7 additions & 0 deletions
7
...ge/src/components/StorageBrowser/useAction/__tests__/__snapshots__/useAction.spec.ts.snap
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,7 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`useAction throws the expected error when called with a type not mapped to an action handler 1`] = `"No handler found for value of \`unexpected!\` provided to \`useAction\`"`; | ||
|
||
exports[`useAction throws the expected error when called with the "listLocationItems" action type 1`] = `"Value of \`listLocationItems\` cannot be provided to \`useAction\`"`; | ||
|
||
exports[`useAction throws the expected error when called with the "listLocations" action type 1`] = `"Value of \`listLocations\` cannot be provided to \`useAction\`"`; |
Oops, something went wrong.