I'm trying to push to an App.js parent component a formed object of the child component with click. As I understand first I should complete the newTask object in the child component and then somehow to push this object to the Tasks object in the parent component.
https://codesandbox.io/s/test-login-page-tasks-rmfn5j?file=/src/components/NewTask.js:316-323
// Child component
const NewTask = ({ authors, tasks }) => {
const [title, setTitle] = useState("");
const [author, setAuthor] = useState("");
const [description, setDescription] = useState("");
const [status, setStatus] = useState(false);
const [priority, setPriority] = useState(false);
const sendTask = () => {
let newTask = {
title: title,
author: author,
description: description,
status: status,
priority: priority
};
};
<input onChange={(e) => setTitle(e.target.value)}/>
<input onChange={(e) => setDescription(e.target.value)}/>
<input onChange={(e) => setStatus(e.target.value)}/>
<input onChange={(e) => setPriority(e.target.value)}/>
<button onClick={sendTask}>Save</button>
}
// App parent component
const Tasks = [ //push newTask to this array
{
id: "001",
status: 0,
priority: 2,
title: "Develop website homepage",
description:
"Create a visually appealing and responsive homepage for the website",
schedule: {
creation_time: "2021-07-23T10:00:00"
},
author_name: "John Smith"
},
{
id: "002",
status: 1,
priority: 1,
title: "Implement user authentication",
description: "Add user authentication feature to the website",
schedule: {
creation_time: "2021-07-24T14:30:00"
},
author_name: "Sarah Lee"
}
]
function App() {
return (
<NewTask authors={Authors} tasks={Tasks} />
)}