App.JS

1 0 0
                                        

// App.js
import React, { Component } from 'react';

class App extends Component {
  state = {
    todos: []
  };/*    This is where the magic happens/*  async componentDidMount() {
    try {
      const res = await fetch('http://127.0.0.1:8000/api/'); // fetching the data from api, before the page loaded
      const todos = await res.json();
      this.setState({
        todos
      });
    } catch (e) {
      console.log(e);
    }
  }

  render() {
    return (
      <div>
        {this.state.todos.map(item => (
          <div key={item.id}>
            <h1>{item.title}</h1>
            <span>{item.description}</span>
          </div>
        ))}
      </div>
    );
  }
}

export default App;

You've reached the end of published parts.

⏰ Last updated: Apr 25, 2024 ⏰

Add this story to your Library to get notified about new parts!

Django (Backend) + React (Fronend) Tutorial BásicoWhere stories live. Discover now