week4.2 React foundation
befor making fullstack application
install these modules
- npm create vite@latest
- npm init/ npm install
- npm install express
- npm install mongoose
- npm install zod
- npm install cors
// todo list app using simple html and js
<!DOCTYPE html><html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
let globalId = 1;
function marAsDone(todoId) {
const parent = document.getElementById(todoId);
parent.children[2].innerHTML = "Done!";
}
function createChild(title, description, id) {
const child = document.createElement("div");
const firstGrandParent = document.createElement("div");
firstGrandParent.innerHTML = title;
const secondGrandParent = document.createElement("div");
secondGrandParent.innerHTML = description;
const thirdGrandParent = document.createElement("div");
thirdGrandParent.innerHTML = "Mark as Done";
thirdGrandParent.setAttribute("onclick", `markAsDone(${id})`);
child.appendChild(firstGrandParent);
child.appendChild(secondGrandParent);
child.appendChild(thirdGrandParent);
child.setAttribute("id", id);
return child;
}
function addTodo() {
const title = document.getElementById("title").value;
const description = document.getElementById("description").value;
//document.createElement
const parent = document.getElementById("todoId");
parent.appendChild(createChild(title, description, globalId++));
}
</script>
</body>
</html>
- npm create vite@latest // to create the frame of react and project name always use this code
- npm install // before running your code
- npm run dev // write this command to run your code
Comments