git clone [email protected]:d8ff27749e32c89a1d23ac7f9e9fbb85.git boundary
pushd boundary && npm install && npm run test
Last active
July 22, 2016 17:02
-
-
Save nsfmc/d8ff27749e32c89a1d23ac7f9e9fbb85 to your computer and use it in GitHub Desktop.
`unstable_handleError` and `ReactDOMServer.renderToString` test case
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"presets": ["es2015", "react"] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 />)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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