Sign up, and you can make all message times appear in your timezone. Sign up
Oct 2, 2022
3:15:45pm
React.js question?

I'm learning react as I go, and I cannot for the life of me figure out how to get an item to render after form submit on a todo list app. Can someone help me? I've looked all over google haha.

import React, { useState } from "react";

function TodoForm({ addTodo }) {

const [input, setInput] = useState("");

const [setTodoArray, todoArray] = useState([]);

const [todo, setTodo] = useState({

id: "",

task: "",

});

functionaddTodo(props) {

props.onAdd(todo);

setTodo({

id: "",

task: "",

});

}

functionhandleSubmit(event) {

letid = Math.floor(Math.random() * 15000);

event.preventDefault();

if (todo.task.trim()) {

addTodo({ ...todo, id });

setTodo({ ...todo, task: "" });

}

console.log({

id,

text: input,

});

setInput("");

}

return (

<div>

<formonSubmit={handleSubmit}>

<header>What do you have to do today?</header>

<input

type="text"

placeholder="Add a task to your list"

value={input}

onChange={(e) =>setInput(e.target.value)}

></input>

<buttontype="button"value="Submit"onClick={handleSubmit}>

Add task

</button>

</form>

</div>

);

}

export default TodoForm;
This message has been modified
Originally posted on Oct 2, 2022 at 3:15:45pm
Message modified by Icelandic Cougar on Oct 2, 2022 at 3:16:07pm
Message modified by Icelandic Cougar on Oct 2, 2022 at 3:17:09pm
Message modified by Icelandic Cougar on Oct 2, 2022 at 3:21:15pm
Message modified by Icelandic Cougar on Oct 2, 2022 at 3:22:06pm
Icelandic Cougar
Previous username
utah is classless
Bio page
Icelandic Cougar
Joined
Jun 8, 2020
Last login
Apr 25, 2024
Total posts
6,308 (60 FO)
Messages
Author
Time

Posting on CougarBoard

In order to post, you will need to either sign up or log in.