-
-
Notifications
You must be signed in to change notification settings - Fork 212
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
No only Error for FallbackProps #83
Comments
That suggested solution sounds fine to me 👍 |
Is it ok if i try to change the error type to unknown in a pull request, in the next coming days? Something in the order of this import React, { useCallback } from "react";
function useErrorHandler(givenError?: unknown): (error: unknown) => void {
const [error, setError] = React.useState<unknown>(givenError ?? null);
if (error !== null) throw error;
const onError = useCallback(
(err: unknown) => {
setError(err ?? null);
},
[]
);
return onError;
} Would you guys accept a pull containing this change ? |
I'm not sure why the function useErrorHandler(
givenError?: unknown,
): React.Dispatch<React.SetStateAction<unknown>> {
const [error, setError] = React.useState<unknown>(null)
if (givenError) throw givenError
if (error) throw error
return setError
} |
In fact, I think it could be further simplified to this: function useErrorHandler(givenError?: unknown) {
const [error, setError] = React.useState<unknown>(null)
if (givenError) throw givenError
if (error) throw error
return setError
} The return type can be inferred without any trouble. |
Should try to explain why i did things ;)
// inferred type
React.Dispatch<React.SetStateAction<unknown>>
// preferred type
(error:unknown) => void
function useErrorHandler(givenError?: unknown) {
const [error, setError] = React.useState<unknown>(null)
if (givenError) throw givenError
if (error) throw error
} ends up in: function useErrorHandler(givenError?: unknown) {
const [error, setError] = React.useState<unknown>(givenError)
if (error) throw error
}
const onError = useErrorHandler();
useEffect(()=>{
function async fetchy() {
promise.catch(onError);
}
fetchy();
}, [onError]) What would happen if the promise was rejected with Sorry should have given explaination in the first place. For me the minimum change you did is also fine but just wanted to give my angle on it ;) |
I guess that's ok
That's not duplication. The suggested change would actually change the behavior. The
I guess that makes sense too. With that, here's a good implementation: function useErrorHandler(givenError?: unknown): (error: unknown) => void {
const [error, setError] = React.useState<unknown>(null)
if (givenError != null) throw givenError
if (error != null) throw error
return setError
} |
And I would consider this a bug fix |
@kentcdodds thanks for the assist and discussion ;), will try to wip up a pull as soon as possible |
🎉 This issue has been resolved in version 3.1.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
I'm using React-query, and we can type our error. But there is a conflit with react-error-boundary since the type is not an Error type, but a custom. How can we deal with that ?
react-error-boundary
version: 3.1.0node
version: 12.19.1npm
version: 6.14.10Relevant code or config
Suggested solution: We can pass our type like :
handleError<ApiError>(err)
OR
The text was updated successfully, but these errors were encountered: