Skip to content

Instantly share code, notes, and snippets.

@juhahinkula
Last active February 26, 2020 10:47
Show Gist options
  • Select an option

  • Save juhahinkula/35eb36bd09c349b178eb3f48bfd1aec3 to your computer and use it in GitHub Desktop.

Select an option

Save juhahinkula/35eb36bd09c349b178eb3f48bfd1aec3 to your computer and use it in GitHub Desktop.
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>React getting started</title>
</head>
<body>
<!-- Root container for react components -->
<div id='root'></div>
<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 src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script>
<script type="text/babel">
function CombineText() {
const {text, setText} = React.useState({posttext: '', pretext: ''});
const {wholetext, setWholeText} = React.useState('');
combineText = () => {
setWholeText(text.pretext + text.posttext);
}
const textChanged = (event) => {
setText({...text, [event.target.id]: event.target.value})
}
return (
<div>
<p>{wholetext}</p>
<input type="text" id="pretext" name="pretext" value={text.pretext} onChange={textChanged} />
<input type="text" id="posttext" name="posttext" value={text.posttext} onChange={textChanged} />
<button onClick={this.combineText}>Press me</button>
</div>
);
}
ReactDOM.render(<CombineText />, document.getElementById('app'));
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment