'Typescript defining a state passed as a prop
export interface ISideBarProps {
open: any
setOpen: any
}
export default function SideBar({ open, setOpen }: ISideBarProps) {
return (
<div
className={`absolute left-0 top-0 h-screen w-[40vw] bg-gray-100 ${open ? "block" : "hidden"}`}
>
Sidebar
</div>
)
}
How would i define open and setopen properly as boolean states
Solution 1:[1]
you can use:
export interface ISideBarProps {
open:boolean,
setOpen:(open:boolean)=>void
}
Solution 2:[2]
Change the type of open and setOpen to boolean instead of any as below.
export interface ISideBarProps {
open: boolean;
setOpen: boolean;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Vida Hedayati |
| Solution 2 | Abhijeet Vadera |
