diff --git a/examples/react/src/Todos.js b/examples/react/src/Todos.js index f9b18b88..1a2bf004 100644 --- a/examples/react/src/Todos.js +++ b/examples/react/src/Todos.js @@ -1,6 +1,6 @@ -import './style.css' import React, { Component } from 'react' import Gun from 'gun' +import './style.css' const formatTodos = todos => Object.keys(todos) .map(key => ({ key, val: todos[key] })) @@ -12,23 +12,28 @@ export default class Todos extends Component { this.gun = gun.get('todos'); this.state = {newTodo: '', todos: []} } + componentWillMount() { this.gun.on(todos => this.setState({ todos: formatTodos(todos) })) } + add = e => { e.preventDefault() this.gun.path(Gun.text.random()).put(this.state.newTodo) this.setState({newTodo: ''}) } + del = key => this.gun.path(key).put(null) + handleChange = e => this.setState({ newTodo: e.target.value}) + render() { return