✅ – fateassassin – 18-10 Jun 5

var todoItems = JSON.parse(localStorage.getItem("todos"));
var id = null;
try{id = todoItems[todoItems.length - 1].id + 1;}
catch{id = 1;}

todoItems.push({
"id": id,
"todo": todo
}
);
alert(JSON.stringify(todoItems));
var todoItems = JSON.parse(localStorage.getItem("todos"));
var id = null;
try{id = todoItems[todoItems.length - 1].id + 1;}
catch{id = 1;}

todoItems.push({
"id": id,
"todo": todo
}
);
alert(JSON.stringify(todoItems));
I've got a question, why does the dict i try to push only contain the ID? It just doesnt contain the todo
Solution:
Message Not Public
Sign In & Join Server To View
Jump to solution
9 Replies
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
[RCON]FateAssassin
[RCON]FateAssassinOP6mo ago
its a state
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
[RCON]FateAssassin
[RCON]FateAssassinOP6mo ago
no, wait
const [todo, setTodo] = useState('');

function addTodo(){
if (todo === '') {
return;
}
if (localStorage.getItem('todos') === null) {
localStorage.setItem('todos', JSON.stringify([]));
}
var todoItems = JSON.parse(localStorage.getItem("todos"));
var id = null;
try{id = todoItems[todoItems.length - 1].id + 1;}
catch{id = 1;}

todoItems.push({
"id": id,
"todo": todo
}
);
alert(JSON.stringify(todoItems));
localStorage.setItem('todos', JSON.stringify(todoItems));
}
const [todo, setTodo] = useState('');

function addTodo(){
if (todo === '') {
return;
}
if (localStorage.getItem('todos') === null) {
localStorage.setItem('todos', JSON.stringify([]));
}
var todoItems = JSON.parse(localStorage.getItem("todos"));
var id = null;
try{id = todoItems[todoItems.length - 1].id + 1;}
catch{id = 1;}

todoItems.push({
"id": id,
"todo": todo
}
);
alert(JSON.stringify(todoItems));
localStorage.setItem('todos', JSON.stringify(todoItems));
}
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
[RCON]FateAssassin
[RCON]FateAssassinOP6mo ago
like this
<div className=' bg-purple-300 p-2 flex justify-center rounded-b-xl mt-2'>
<input type='text' className='ml-10 mr-3 p-1 rounded-md focus:bg-gray-100 focus:outline-none' value={todo} required onChange={(e) => setTodo(e.value)} placeholder='Add ToDo'/>
<button className='mr-10 ml-3 bg-blue-300 rounded-xl py-1 px-3 font-semibold active:bg-blue-400 active:text-blue-900 duration-75' onClick={addTodo}>Add</button>
</div>
<div className=' bg-purple-300 p-2 flex justify-center rounded-b-xl mt-2'>
<input type='text' className='ml-10 mr-3 p-1 rounded-md focus:bg-gray-100 focus:outline-none' value={todo} required onChange={(e) => setTodo(e.value)} placeholder='Add ToDo'/>
<button className='mr-10 ml-3 bg-blue-300 rounded-xl py-1 px-3 font-semibold active:bg-blue-400 active:text-blue-900 duration-75' onClick={addTodo}>Add</button>
</div>
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
[RCON]FateAssassin
[RCON]FateAssassinOP6mo ago
Ahh thanks, i appreciate it
reactibot
reactibot6mo ago
This question has an answer! Thank you for helping 😄 If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1247975947714428978