Skip to content

Commit b46bc66

Browse files
author
Joschua Schneider
authored
Merge pull request #11 from JoschuaSchneider/move-to-typescript
Move to typescript
2 parents f1fdd37 + 1f14077 commit b46bc66

22 files changed

+9324
-5813
lines changed

.github/workflows/npm-publish.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Publish package to npm on new release.
2+
3+
name: Node.js Package
4+
5+
on:
6+
release:
7+
types: [created]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: actions/setup-node@v1
15+
with:
16+
node-version: 12
17+
- run: npm ci
18+
- run: npm test
19+
20+
publish-npm:
21+
needs: build
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v2
25+
- uses: actions/setup-node@v1
26+
with:
27+
node-version: 12
28+
registry-url: https://registry.npmjs.org/
29+
- run: npm ci
30+
- run: npm publish
31+
env:
32+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}

.prettierrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
22
"semi": false
3-
}
3+
}

.travis.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

README.md

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ It lets you keep track of the error state of child components, by wrapping them
1616
npm i use-error-boundary
1717
```
1818

19+
### Breaking changes in `2.x`
20+
21+
If you are upgrading from version `1.x` please make sure you are not using the `errorInfo` object.
22+
The hook itself and the `renderError` callback no longer provide this object.
23+
24+
For advanced use, please refer to [Custom handling of error and errorInfo](#custom-handling-of-error-and-errorinfo).
25+
1926
## Examples and usage
2027

2128
Import the hook:
@@ -35,8 +42,7 @@ const MyComponent = () => {
3542
const {
3643
ErrorBoundary,
3744
didCatch,
38-
error,
39-
errorInfo
45+
error
4046
} = useErrorBoundary()
4147

4248
...
@@ -85,11 +91,23 @@ Optionally, you can pass a `render` and `renderError` function to render the com
8591
return (
8692
<ErrorBoundary
8793
render={() => <SomeChild />}
88-
renderError={({ error, errorInfo }) => <MyErrorComponent error={error} />}
94+
renderError={({ error }) => <MyErrorComponent error={error} />}
8995
/>
9096
)
9197
```
9298

99+
## Custom handling of `error` and `errorInfo`
100+
101+
The hook now accepts an `options` object that you can pass a `onDidCatch` callback that gets called when the ErrorBoundary catches an error.
102+
103+
```js
104+
useErrorBoundary({
105+
onDidCatch: (error, errorInfo) => {
106+
// For logging/reporting
107+
},
108+
})
109+
```
110+
93111
## Returned Properties
94112

95113
These are the properties of the returned Object:
@@ -99,7 +117,8 @@ These are the properties of the returned Object:
99117
| `ErrorBoundary` | React Component | Special error boundary component that provides state changes to the hook. <br>:warning: **You need to use this as the error boundary! Otherwise, the state will not update when errors are catched!** <br> The ErrorBoundary is **guaranteed referential equality** across rerenders. |
100118
| `didCatch` | Boolean | `true` if an error has been catched |
101119
| `error` | Error Object or `null` | The error catched by the Boundary |
102-
| `errorInfo` | Object or `null` | Error Info from the boundary ([React docs](https://reactjs.org/docs/error-boundaries.html)) |
120+
121+
If you are searching for the `errorInfo` property, please read [Breaking Changes in 2.x](#breaking-changes-in-2x).
103122

104123
## Why should I use this?
105124

@@ -110,6 +129,6 @@ This packages purpose is to provide an easy drop in replacement for projects tha
110129

111130
## Contributing
112131

113-
Contributions are welcome, as this is my **first properly published npm package**.
132+
Contributions are always welcome.
114133

115-
Feel free to open issues or pull requests! I will review them as fast as possible.
134+
Feel free to open issues or pull requests!

babel.config.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

jest.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
preset: "ts-jest",
3+
testEnvironment: "jsdom",
4+
setupFilesAfterEnv: ["@testing-library/jest-dom/extend-expect"],
5+
}

0 commit comments

Comments
 (0)