Reputation: 223
Checked other stackoverflow posts regarding this error and I still dont get it. This block of code is getting the error.
const [user, setUser] = useState<User>({})
I mapping over card component that needs the props from the user data. Why isn't this working?
Also i have a home page that grabs all the user with this block of code and i dont get the type error.
const [users, setUsers] = useState<User[]>([])
Why am i not getting such error on that?
Upvotes: 0
Views: 3518
Reputation: 190966
In your first example, your object is missing the required properties or is not instanceof User
.
In your 2nd example, thats just an empty array so that will work. In that case, User
describes the type requirement for the items.
Upvotes: 2