I’m trying to type a function in the child component that returns an object, but I’m getting the error Expected 0 arguments, but got 1 in the handler function. Even though I’m typing the function received from props at the top of the code, expecting it to return an object required.
import React, { useState, FC } from "react";
type Tasks = {
title: string;
author: string;
description: string;
status: string;
priority: string;
};
type Props = {
Tasks: Tasks[];
changeTask: () => {};
};
const TaskComponent: FC<Props> = ({ Tasks, changeTask }) => {
const task = Tasks.find((task) => String(task.id) === id);
const handleSaveTask = (event) => {
event.preventDefault();
changeTask({
...task,
status,
priority
});
};
return (
<form onSubmit={handleSaveTask}>
...
</form>
)
2
Answers
As @Niklas suggested, how about changing the type of
changeTask
?Example:
Also, you are using the name
Tasks
for type and a variable. I would suggest changing either of them.However when called on 2 -> an argument has been passed which does not match the signature