import { useState, useEffect } from "react";
export default function App() {
const [tasks, setTasks] = useState(null);
useEffect(() => {
const keys = ["one", "two", "three"];
const array = [];
for (let taskText of keys) {
let ob = { text: taskText, key: Date.now() };
array.push(ob);
}
setTasks(array);
}, []);
useEffect(() => {
if (tasks) {
console.log(tasks);
}
}, [tasks]);
return null;
}
import React from 'react';
export function App() {
const [list, setItem] = React.useState([]);
let tasks = [];
React.useEffect(() => {
const keys = ["one", "two", "three"];
for (let taskText of keys) {
let ob = {text: taskText, key: Date.now()};
tasks.push(ob);
}
setItem(tasks)
}, [])
React.useEffect(() => {
console.log(tasks)
}, [])
return null;
}