reactjs - How to destructure useContext hook in Typescript with null default value? - Stack Overflow

PHOTO EMBED

Tue Aug 02 2022 13:45:35 GMT+0000 (Coordinated Universal Time)

Saved by @jhonataspaulo #javascript

function UserResults() {
  const appContext = useContext(GithubContext)

  const { users, loading, fetchUsers } = appContext
  

  useEffect(() => {
    fetchUsers()
  }, [fetchUsers])

  if (!loading) {
    return (
      <div className='grid grid-cols-1 gap-8 xl:grid-cols-4 lg:grid-cols-3 md:grid-cols-2'>
        {users.map((user : User) => (
          <UserItem key={user.id} user={user} />
        ))}
      </div>
    )
  } else {
    return <Spinner />
  }
}
content_copyCOPY

https://stackoverflow.com/questions/73208538/how-to-destructure-usecontext-hook-in-typescript-with-null-default-value