reactjs - Simple react todo app and storing todos in firebase -
i have simple todo app trying 'todos' stored in firebase. here relevant files...
base.js
import rebase 're-base'; import firebase 'firebase'; const app = firebase.initializeapp({ apikey: "mykey", authdomain: "myapp.firebaseapp.com", databaseurl: "https://myapp.firebaseio.com", }); const base = rebase.createclass(app.database()); export default base; todolist.js
import react, { component } 'react'; import todoitems './todoitems'; import todoinput './todoinput'; import base './base'; class todolist extends react.component { static proptypes = { todos: react.proptypes.array }; constructor(props) { super(props) this.state = { todos: this.props.todos || [] } } componentwillmount(){ this.ref = base.syncstate({ context: this, state: 'todos' }); } addtodo = (item) => { this.setstate({todos: this.state.todos.concat([item])}); } render () { return ( <div> <h3>todo list</h3> <todoitems items={this.state.todos}/> <todoinput addtodo={this.addtodo}/> </div> ); } }; export default todolist; the error getting is:
rebase: firebase endpoint trying listen must string. instead, got [object object] in this.ref = base.syncstate({. dubious this.ref not sure put in stead. ideas appreciated.
the issue having when calling syncstate in componentwillmount need pass 2 arguments, first being firebase endpoint. solution below...not added /todos first argument.
componentwillmount(){ this.ref = base.syncstate('/todos', { context: this, state: 'todos' }); } wiki
Comments
Post a Comment