-
Notifications
You must be signed in to change notification settings - Fork 236
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
Add onError
prop to LiveProvider
#163
base: master
Are you sure you want to change the base?
Conversation
I think |
Just added some more fixes. Forgot about this PR for a while, sorry! The I do need to add documentation, agreed! |
README.md
Outdated
@@ -156,6 +156,8 @@ It supports these props, while passing any others through to the `children`: | |||
|scope|PropTypes.object|Accepts custom globals that the `code` can use | |||
|noInline|PropTypes.bool|Doesn’t evaluate and mount the inline code (Default: `false`). Note: when using `noInline` whatever code you write must be a single expression (function, class component or some `jsx`) that can be returned immediately. If you'd like to render multiple components, use `noInline={true}` | |||
|transformCode|PropTypes.func|Accepts and returns the code to be transpiled, affording an opportunity to first transform it | |||
|onError|PropTypes.func|Called with `Error` object when render fails. Allows you to listen for errors and implement custom logic.| | |||
|onRender|PropTypes.func|Called when component is rendered successfully. Can be used alongside `onError` to clear own error state.| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we could use onError
for this same purpose? If onRender
is called really only when render is called successfully (presumably after error) could we instead just call onError
again with the default state such as { error: undefined }
. If I understand the point of this prop correctly I could imagine just resetting the error state would be sufficient for clearing any external error states?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, that's definitely doable!
I'm thinking it might be a tad confusing to call it onError
when it doesn't explicitly emit errors though. Maybe having the function signature be onRender(error?: Error) => void
would make more sense? From first glance you'd be able to see what the event is about, and that it can emit both error and non-error state.
Let me know what you'd prefer and I'll make the updates. 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about onChange(code: string, error?: Error)
@sofiapoh I removed |
This is a great addition. Any update here? |
I need a way to get the
Error
object instead of just rendering it through<LiveError />
. I couldn't find a way to do this so I thought I'd add simpleonError
+onRender
props toLiveProvider
. Devs can then set these handlers if they want to do some custom error handling.Please let me know if I missed anything or if you don't feel this is a good addition.