DEV Community

Cover image for build a Simple Todo with ReactJs Angular VueJs
nour
nour

Posted on Edited on

build a Simple Todo with ReactJs Angular VueJs

Introduction

todoApps are a classic project for learning new frameworks and building one with Reactjs & Angular & Vue can provide valuable insights into the strengths and differences of each. in this Post we will walk through the process of creating a basic todo app with each of these popular frameworks and we'll delve into the differences between these popular frameworks and explore their strengths and use cases.

Note
Before you start make sure u have Nodejs and npm installed

1. Creating the Project:

React :

npx create-react-app todo-react
cd todo-react

🔥 Jadwal & Hasil: nourbouch/building a simple todoapp with reactjs angular and vuejs b - Pertandingan Hari Ini 🔥 Jadwal & Hasil: nourbouch/building a simple todoapp with reactjs angular and vuejs b - Pertandingan Hari Ini

Angular :

npm install -g @angular/cli
ng new todo-angular
cd todo-angular

🔥 Jadwal & Hasil: nourbouch/building a simple todoapp with reactjs angular and vuejs b - Pertandingan Hari Ini 🔥 Jadwal & Hasil: nourbouch/building a simple todoapp with reactjs angular and vuejs b - Pertandingan Hari Ini

Vue :

npm install -g @vue/cli
vue create todo-vue
cd todo-vue

🔥 Jadwal & Hasil: nourbouch/building a simple todoapp with reactjs angular and vuejs b - Pertandingan Hari Ini 🔥 Jadwal & Hasil: nourbouch/building a simple todoapp with reactjs angular and vuejs b - Pertandingan Hari Ini

2. Implementing the Todo List:

React :

import React, { useState } from 'react';
function App() {
  const [todos, setTodos] = useState([]);
  const [inputValue, setInputValue] = useState('');

  const addTodo = () => {
    setTodos([...todos, inputValue]);
    setInputValue('');
  };

  const removeTodo = (index) => {
    const newTodos = [...todos];
    newTodos.splice(index, 1);
    setTodos(newTodos);
  };
  return (
    <div>
      <input
        type="text"
        value={inputValue}
        onChange={(e) => setInputValue(e.target.value)}
      />
      <button onClick={addTodo}>Add</button>
      <ul>
        {todos.map((todo, index) => (
          <li key={index}>
            {todo} <button onClick={() => removeTodo(index)}>Remove</button>
          </li>
        ))}
      </ul>
    </div>
  );
}
export default App;

🔥 Jadwal & Hasil: nourbouch/building a simple todoapp with reactjs angular and vuejs b - Pertandingan Hari Ini 🔥 Jadwal & Hasil: nourbouch/building a simple todoapp with reactjs angular and vuejs b - Pertandingan Hari Ini

Angular :

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  todos: string[] = [];
  inputValue: string = '';

  addTodo() {
    this.todos.push(this.inputValue);
    this.inputValue = '';
  }

  removeTodo(index: number) {
    this.todos.splice(index, 1);
  }
}

🔥 Jadwal & Hasil: nourbouch/building a simple todoapp with reactjs angular and vuejs b - Pertandingan Hari Ini 🔥 Jadwal & Hasil: nourbouch/building a simple todoapp with reactjs angular and vuejs b - Pertandingan Hari Ini
<input type="text" [(ngModel)]="inputValue">
<button (click)="addTodo()">Add</button>
<ul>
  <li *ngFor="let todo of todos; let i = index">
    {{ todo }} <button (click)="removeTodo(i)">Remove</button>
  </li>
</ul>

🔥 Jadwal & Hasil: nourbouch/building a simple todoapp with reactjs angular and vuejs b - Pertandingan Hari Ini 🔥 Jadwal & Hasil: nourbouch/building a simple todoapp with reactjs angular and vuejs b - Pertandingan Hari Ini

Vue :

<template>
  <div>
    <input type="text" v-model="inputValue">
    <button @click="addTodo">Add</button>
    <ul>
      <li v-for="(todo, index) in todos" :key="index">
        {{ todo }} <button @click="removeTodo(index)">Remove</button>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  data() {
    return {
      todos: [],
      inputValue: ''
    };
  },
  methods: {
    addTodo() {
      this.todos.push(this.inputValue);
      this.inputValue = '';
    },
    removeTodo(index) {
      this.todos.splice(index, 1);
    }
  }
}
</script>

🔥 Jadwal & Hasil: nourbouch/building a simple todoapp with reactjs angular and vuejs b - Pertandingan Hari Ini 🔥 Jadwal & Hasil: nourbouch/building a simple todoapp with reactjs angular and vuejs b - Pertandingan Hari Ini

3. Running the App :

React :

npm start

🔥 Jadwal & Hasil: nourbouch/building a simple todoapp with reactjs angular and vuejs b - Pertandingan Hari Ini 🔥 Jadwal & Hasil: nourbouch/building a simple todoapp with reactjs angular and vuejs b - Pertandingan Hari Ini

Angular :

npm start || ng serve

🔥 Jadwal & Hasil: nourbouch/building a simple todoapp with reactjs angular and vuejs b - Pertandingan Hari Ini 🔥 Jadwal & Hasil: nourbouch/building a simple todoapp with reactjs angular and vuejs b - Pertandingan Hari Ini

Vue :

npm run serve

🔥 Jadwal & Hasil: nourbouch/building a simple todoapp with reactjs angular and vuejs b - Pertandingan Hari Ini 🔥 Jadwal & Hasil: nourbouch/building a simple todoapp with reactjs angular and vuejs b - Pertandingan Hari Ini

congratulations you have successfully built a simple todo app using React & Angular & Vue

Top comments (0)