-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(react)!: query error resetter
- Loading branch information
Showing
5 changed files
with
44 additions
and
73 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,5 @@ | ||
--- | ||
"@reactive-dot/react": minor | ||
--- | ||
|
||
BREAKING: The query error resetter no longer accepts a specific error input; it now defaults to resetting all errors globally. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
import { resetQueryError } from "../utils/jotai.js"; | ||
import { atomFamilyErrorsAtom } from "../utils/jotai.js"; | ||
import { useAtomCallback } from "jotai/utils"; | ||
import { useCallback } from "react"; | ||
|
||
/** | ||
* Hook for getting function to reset query error caught by error boundary | ||
* | ||
* @returns Function to reset caught query error | ||
*/ | ||
// eslint-disable-next-line @eslint-react/hooks-extra/no-redundant-custom-hook | ||
export function useQueryErrorResetter() { | ||
return resetQueryError; | ||
return useAtomCallback( | ||
useCallback((get) => { | ||
const atomFamilyErrors = get(atomFamilyErrorsAtom); | ||
|
||
for (const error of atomFamilyErrors) { | ||
error.atomFamily.remove(error.param); | ||
atomFamilyErrors.delete(error); | ||
} | ||
}, []), | ||
); | ||
} |
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