import React, { Component } from 'react' import Gun from 'gun/gun' import path from 'gun/lib/path' import './style.css' const formatTodos = todos => Object.keys(todos) .map(key => ({ key, val: todos[key] })) .filter(t => Boolean(t.val) && t.key !== '_') export default class Todos extends Component { constructor({gun}) { super() 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

} }