Skip to content

Instantly share code, notes, and snippets.

@lifez
Created February 9, 2017 05:26
Show Gist options
  • Select an option

  • Save lifez/a0f66131ada73116ec49ca4ff80d890a to your computer and use it in GitHub Desktop.

Select an option

Save lifez/a0f66131ada73116ec49ca4ff80d890a to your computer and use it in GitHub Desktop.
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