Created
October 20, 2018 15:57
-
-
Save valex/aea28755240d4219441d15f9effd9d03 to your computer and use it in GitHub Desktop.
Stateless component
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Stateless</title> | |
<meta charset="utf-8"> | |
<style> | |
body, textarea { | |
font-family: Courier; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="app"> | |
<!-- my app renders here --> | |
</div> | |
<script crossorigin src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script> | |
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script> | |
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script> | |
<script crossorigin src="https://cdnjs.cloudflare.com/ajax/libs/prop-types/15.6.2/prop-types.min.js"></script> | |
<script type="text/babel"> | |
class TextAreaCounter extends React.Component { | |
static defaultProps = { | |
text: '' | |
}; | |
render() { | |
return ( | |
<div> | |
<textarea defaultValue={this.props.text}></textarea> | |
<h3>{this.props.text.length}</h3> | |
</div> | |
); | |
} | |
} | |
TextAreaCounter.propTypes = { | |
text: PropTypes.string | |
}; | |
ReactDOM.render( | |
React.createElement(TextAreaCounter, { | |
text: "Bob", | |
}), | |
document.getElementById("app") | |
); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment