Skip to content

Instantly share code, notes, and snippets.

@nsfmc
Last active July 22, 2016 17:02
Show Gist options
  • Save nsfmc/d8ff27749e32c89a1d23ac7f9e9fbb85 to your computer and use it in GitHub Desktop.
Save nsfmc/d8ff27749e32c89a1d23ac7f9e9fbb85 to your computer and use it in GitHub Desktop.
`unstable_handleError` and `ReactDOMServer.renderToString` test case
{
"presets": ["es2015", "react"]
}
git clone [email protected]:d8ff27749e32c89a1d23ac7f9e9fbb85.git boundary
pushd boundary && npm install && npm run test
import React from 'react';
import ReactDOMServer from 'react-dom/server';
class Angry extends React.Component {
render() {
throw new Error('Please, do not render me.');
}
}
class Boundary extends React.Component {
constructor(props) {
super(props);
this.state = {error: false};
}
render() {
if (!this.state.error) {
return (<div><button onClick={this.onClick}>ClickMe</button><Angry /></div>);
} else {
return (<div>Happy Birthday!</div>);
}
}
onClick() {
/* do nothing */
}
unstable_handleError() {
this.setState({error: true});
}
}
console.log(ReactDOMServer.renderToString(<Boundary />))
{
"name": "boundary",
"version": "1.0.0",
"description": "",
"main": "index.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "babel-node index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"babel-cli": "^6.11.4",
"babel-preset-es2015": "^6.9.0",
"babel-preset-react": "^6.11.1",
"react": "^15.2.1",
"react-dom": "^15.2.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment