Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, {Component} from 'react';
- // import webdevlogo from './components/webdevlogo.png';
- import './todo.css';
- // import Todo from './components/todo.js';
- class Todo extends Component {
- // constructor(props){
- // super(props);
- // this.state = {
- // todos: [],
- // description: "",
- // class_name: "",
- // priority: "",
- // completed: false
- // };
- // // this.handleSubmit = this.handleSubmit.bind(this);
- // }
- // handleSubmit(event){
- // event.preventDefault();
- // const form = document.getElementById("newTask").value;
- // if (this.state.todos.find(todos => todos.description == form)){
- // this.setState({description : form });
- // }else {
- // fetch("/api/addpost/" + form)
- // .then(response => response.json())
- // .then(stats => {
- // console.log("all todos fetched: ");
- // console.log(todos);
- // this.setState({ todos: todos });
- // });
- // this.setState({ description : form });
- // }
- // }
- componentDidMount(){
- fetch("api/todos")
- .then(response =>{
- if(response.status !== 200) {
- console.log("there was an issue - status code: " +response.status);
- return;
- }
- response.json().then(todos => {
- console.log("all tasks fetched: ");
- console.log(todos);
- this.setState({ todos : todos });
- });
- })
- .catch(err => {
- console.log("tasks fetch error :-S", err);
- });
- }
- render(){
- return(
- <div className="App">
- <Todo />
- </div>
- );
- }
- }
- export default Todo;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement