Babel plugin to add source fiber for use in componentDidCatch
npm install babel-plugin-component-did-catch-source> Add fiber source to componentDidCatch info argument.
``sh`
npm install --save-dev babel-plugin-component-did-catch-source
Need access to the source fiber but react's componentDidCatch does not provide it. Maintaining a fork of React is not as flexible as a compile time change.
Before
`jsx`
class ErrorBoundary extends Component {
componentDidCatch(error, { componentStack }) {
errorLogger(componentStack)
}
}
After
`jsx
class ErrorBoundary extends Component {
componentDidCatch(error, { componentStack, source }) {
const { props, state } = source.stateNode
errorLogger(componentStack, props, state)
}
}
`
.babelrc
`json`
{
"env": {
"production": {
"plugins": ["component-did-catch-source"]
}
}
}
`sh`
babel --plugins component-did-catch-source script.js
`js``
require('babel-core').transform('code', {
plugins: [
'component-did-catch-source',
],
});
None yet
This plugin will likely only work with v16 of React.
MIT