Created
February 9, 2017 05:26
-
-
Save lifez/a0f66131ada73116ec49ca4ff80d890a to your computer and use it in GitHub Desktop.
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, { Component } from 'react'; | |
| import logo from './logo.svg'; | |
| import './App.css'; | |
| class App extends Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { value: ''}; | |
| this.handleClick = this.handleClick.bind(this); | |
| } | |
| handleChange(event) { | |
| this.setState({ value: event.target.value }); | |
| } | |
| handleClick() { | |
| fetch(`http://localhost:3000/posts/${this.state.value}`) | |
| .then(function (response) { | |
| return response.text() | |
| }).then(function (body) { | |
| document.body.innerHTML = body | |
| }) | |
| } | |
| render() { | |
| return ( | |
| <div className="App"> | |
| <div className="App-header"> | |
| <img src={logo} className="App-logo" alt="logo" /> | |
| <h2>Welcome to React</h2> | |
| </div> | |
| <p className="App-intro"> | |
| <input type="text" value={this.state.value} onChange={this.handleChange.bind(this)} /> | |
| <button onClick={this.handleClick}>CLICK!</button> | |
| To get started, edit <code>src/App.js</code> and save to reload. | |
| </p> | |
| </div> | |
| ); | |
| } | |
| } | |
| export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment