Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What's with the type error in Explore? #57

Open
Vidhanvyrs opened this issue Apr 29, 2024 · 3 comments
Open

What's with the type error in Explore? #57

Vidhanvyrs opened this issue Apr 29, 2024 · 3 comments

Comments

@Vidhanvyrs
Copy link

so initially everything was running great for months but now suddenly this error is showing up whenever an user tries to click on explore
image
here is the gridposlist code of mine

import { useUserContext } from "@/context/AuthContext";
import { Models } from "appwrite";
import { Link } from "react-router-dom";
import PostStats from "./PostStats";

type GridPostListProps = {
  posts: Models.Document[];
  showUser?: boolean;
  showStats?: boolean;
};
const GridPostList = ({
  posts,
  showUser = true,
  showStats = true,
}: GridPostListProps) => {
  const { user } = useUserContext();
  return (
    <ul className="grid-container">
      {posts.map((post) => (
        <li key={post.$id} className="relative min-w-80 h-80">
          <Link to={`/posts/${post.$id}`} className="grid-post_link">
            <img
              src={post?.imageUrl}
              alt="post"
              className="object-cover w-full h-full"
            />
          </Link>

          <div className="grid-post_user">
            {showUser && (
              <div className="flex items-center justify-start flex-1 gap-2">
                <img
                  src={post.creator.imageUrl}
                  alt="creator"
                  className="w-8 h-8 rounded-full"
                />
                <p className="line-clamp-1">
                  {post.creator.name || "/assets/icons/profile-placeholder.svg"}
                </p>
              </div>
            )}
            {showStats && <PostStats post={post} userId={user.id} />}
          </div>
        </li>
      ))}
    </ul>
  );
};

export default GridPostList;
@Godswork4
Copy link

Getting the same error on my end, can it be due to an update in

@Godswork4
Copy link

image

Check out this image, you need to pass the waiting optional symbol ? into the code like post?.creator?
This ensures that if post.creator is null or undefined, a placeholder image and name are used instead.

@Vidhanvyrs
Copy link
Author

Thankyou Its working now 👍🤗🥂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants