I’m trying to pass my setState function to a child component, but when I pass it down, I get two typescript errors: Cannot find name ‘Dispatch’.ts(2304) and Cannot find name ‘SetStateAction’.ts(2304)
Does anyone know how to fix this?
// page.tsx
import { useState } from 'react';
export default function Page() {
const [jobs, setJobs] = useState([]);
return (
<JobMenubar jobs={jobs} setJobs={setJobs} />
)
}
// JobMenubar.tsx
type Props = {
jobs: string[]
setJobs: Dispatch<SetStateAction<never[]>> // Cannot find name 'Dispatch'.ts(2304) and Cannot find name 'SetStateAction'.ts(2304)
}
export default function JobMenubar({ filteredJobs, setFilteredJobs } : Props) {
return (
// ...
)
}
>Solution :
I use Dispatch from my provider.
export type ObjectSend = {
idDocumento: Guid;
Url: string;
Name: string;
};
import {
SetStateAction,
Dispatch } from "react";
setChecked: Dispatch<SetStateAction<ObjectSend[]>>;