japgolly / scalajs-react

Facebook's React on Scala.JS
https://japgolly.github.io/scalajs-react/
Apache License 2.0
1.64k stars 231 forks source link

Provide default IO/SyncIO error handler for component #1084

Open matthughes opened 1 year ago

matthughes commented 1 year ago

Maybe this is already possible but I'd love to be able to have a default error handler for any IO/SyncIO/Callback effect. Something like:

    ScalaComponent
      .builder[Props]("MyComponent")
      .initialState(State.Initial)
      .renderBackend[Backend]
      .onError(s => s.backend.handleError(s.error))

This would be akin to adding.onError to every effect you submit (onClick/componentDidMethods). I have to believe there is a way to do this with the Dispatch/Effect classes but can't quite figure it out. Would be great to have a more ergonomic way though. If someone could generally point my in a direction I can try to submit a PR.