render todo list

This commit is contained in:
davidwells 2018-06-11 17:40:42 -07:00
parent 0d0e8a8a62
commit 19b077f48a

View file

@ -3,14 +3,31 @@ import logo from './logo.svg'
import './App.css'
class App extends Component {
state = {
todos: []
}
componentDidMount() {
console.log('fetch items')
fetch('https://adoring-clarke-f30908.netlify.com/.netlify/functions/todos-read-all')
fetch('/.netlify/functions/todos-read-all')
.then((response) => {
console.log(response)
return response.json()
})
.then((myJson) => {
console.log(myJson)
this.setState({
todos: myJson.data
})
})
}
renderTodos() {
const { todos } = this.state
return todos.map((todo, i) => {
return (
<div key={i}>
{todo['@ref']}
</div>
)
})
}
render() {
@ -23,6 +40,7 @@ class App extends Component {
<p className="App-intro">
Using FaunaDB & netlify functions
</p>
{this.renderTodos()}
</div>
)
}