The Only Right Way To Handle Errors in React - No More Error Boundaries

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ก.ย. 2024

ความคิดเห็น • 40

  • @aristosxanthus658
    @aristosxanthus658 ปีที่แล้ว +7

    I never knew how to actually use React Error Boundary until now. Also didn't know how much of an improvement it is over the native React error boundary. Thanks for the knowledge.

  • @rishabh7g
    @rishabh7g 7 หลายเดือนก่อน +1

    Thank you, CoderOne, for making this video. Because of you, I am able to understand the error handling in React completely.

  • @RichardTan-s9f
    @RichardTan-s9f ปีที่แล้ว +11

    Are you sure the async code won't trigger the error boundary? It looked to me like the error was being swallowed by your try catch

  • @nickwoodward819
    @nickwoodward819 ปีที่แล้ว +2

    This also works I think:
    const useThrowAsyncError = () => {
    const [state, setState] = useState();
    return (error) => {
    setState(() => throw error)
    }
    }

  • @PlacidRodrigues1
    @PlacidRodrigues1 8 หลายเดือนก่อน +1

    The standard error boundary can surely handle async errors and it can show fallbacks. You have mistakenly swallowed the error in the catch block.

  • @samirshrestha5252
    @samirshrestha5252 ปีที่แล้ว +1

    Hello there, I am beginner learner of react. please make separate tutorial on react-error-boundary, describing everything. I hope new tutorial on react-error-boundary will come soon.

  • @benoitgrasset
    @benoitgrasset ปีที่แล้ว

    doest it work with NextJS ?

  • @kushbhandari9249
    @kushbhandari9249 ปีที่แล้ว +1

    Isn't it better to use Redux and Axios Instance(Interceptors) for async error handling.

    • @kakun7238
      @kakun7238 ปีที่แล้ว

      redux or interceptor ma rakhyo bhane ta harek euta component ma gayera feri error ko lagi ui milairakhnu paryo tyo package use garyo bhane kunai component ma error aaye ni tesle handle gardincha so tyo sajilo bhayo

    • @ejikemekingson6336
      @ejikemekingson6336 ปีที่แล้ว

      I don't think that caters for "render errors" as well. Just errors during API calls.

  • @ne1butu1
    @ne1butu1 10 หลายเดือนก่อน

    What you explain in what React tells you to use for 'ErrorBoundary' is fucking baffling. Thanks for helping me understand this, so I now need to wrap the child and not use the async that should be throwing it... Makes sense. Thank you.

  • @favouritejome
    @favouritejome ปีที่แล้ว +14

    I've been using the react error boundary but didn't know it could catch errors from async operations, also I didn't know of the limitation of the error boundary. Thanks for the video

  • @nickwoodward819
    @nickwoodward819 10 หลายเดือนก่อน +2

    Using the native error boundaries you can render a fallback element:
    ``

  • @mashup_editor
    @mashup_editor ปีที่แล้ว +2

    You can use a function component as a fallback in the native error boundary... I don't see the point in downloading an extra bloating package, am I missing something?

  • @anonymousBl1
    @anonymousBl1 ปีที่แล้ว +2

    Is the react-error-boundary library a good replacement for the built-in React ErrorBoundary component if:
    - you would like a fallback ui for asynchronous error as well as regular errors
    - if you don't like to use React class components
    Did i understand that correctly anything else i am missing?

    • @aristosxanthus658
      @aristosxanthus658 ปีที่แล้ว +1

      Yes, it can handle both types of errors, used as hooks instead of class components

  • @jaroslavhuss7813
    @jaroslavhuss7813 ปีที่แล้ว +1

    Well, what I do - I have a global reduxToolkit state just for error and if anything sh1tty happens in try/catch + fetch, I will just return that error to the redux error component which displays the error message to the user as a modal. I will look at this though. I did not know about this library. Thank you!

  • @aname3351
    @aname3351 หลายเดือนก่อน

    Hey. Nice video! However i have a feeling that if you would throw an error in catch after fetch items, the native react boundry would pick it up. This is the the step you also need to do using library (calling method from hook).

  • @frontendlogic
    @frontendlogic 4 หลายเดือนก่อน

    There is a problem with example 2. You passed the error to the catch block and did nothing with it. How do you expect it to be caught by the ErrorBoundary?

  • @sashasyhinin3928
    @sashasyhinin3928 8 หลายเดือนก่อน +1

    Why did you delete my comment? where i mentioned on mistake in you video

    • @sarthakghoshal-l4n
      @sarthakghoshal-l4n 4 หลายเดือนก่อน

      What was the mistake? I want to know so I can keep a look out

  • @Adidobro
    @Adidobro ปีที่แล้ว +14

    speaking about junior mistakes while using any types anywhere...

    • @FEA5T
      @FEA5T 11 หลายเดือนก่อน

      So, because he points out a junior mistake, that means he cant also make a mistake? Junior devs cant recognize junior mistakes? If I may say so, that is junior dev type of thinking 🤌

  • @tjcn
    @tjcn 5 หลายเดือนก่อน

    *caught

  • @Saadhya-p8o
    @Saadhya-p8o 8 หลายเดือนก่อน

    its not working for me to handle async operation. please help

  • @kubwimanapatrick5425
    @kubwimanapatrick5425 ปีที่แล้ว

    Greate video .... Can you please share the repo for this example

  • @khale-d
    @khale-d 5 หลายเดือนก่อน

    Awesome video, thanks so much

  • @mathewuy527
    @mathewuy527 ปีที่แล้ว

    awesome video new subscriber here thank you

  • @mhrdkk
    @mhrdkk 8 หลายเดือนก่อน

    Thank you, it's helpful

  • @大盗江南
    @大盗江南 3 หลายเดือนก่อน

    thank bro!

  • @momendaoud9561
    @momendaoud9561 ปีที่แล้ว

    Amazing video please keep doing videos like this

  • @eligbuefelix7988
    @eligbuefelix7988 ปีที่แล้ว

    I love this topic. An advanced concept

  • @shafqatrasool662
    @shafqatrasool662 ปีที่แล้ว

    thanks amazing info keep it up!

  • @arihantjain8347
    @arihantjain8347 ปีที่แล้ว

    Thanks alot

  • @rodrigoorellana2389
    @rodrigoorellana2389 ปีที่แล้ว

    awesome!

  • @dat1309
    @dat1309 ปีที่แล้ว

    Thanks you so much

  • @jotasenator
    @jotasenator ปีที่แล้ว

    i like it!!

  • @suyashsrivastava3671
    @suyashsrivastava3671 ปีที่แล้ว +2

    I prefer the first way , better for showing different custom error ui in different cases , gives more independence

  • @story_of_us_
    @story_of_us_ ปีที่แล้ว

    Hi, love the content, appreciated a lot! Btw I really like your editor's theme, do you mind share it to me please? Thank you!