Attempting to use objects as children in React components will result in an error, especially when working with

I encountered an error message stating: Objects are not valid as a React child (found: object with keys {image, name}). If you intended to render a collection of children, use an array instead.

I am unsure about what I am missing.

The code below is functioning properly:

interface Props {
  posts: [Post]
}

const Home: NextPage<Props> = ({ posts }) => {
  return (
    <div className="mx-auto max-w-7xl">
      <Head>
        <title>Medium Blog</title>
        <link rel="icon" href="/favicon.ico" />
      </Head>
      <Header />
      <div className="flex items-center justify-between border-y border-black bg-yellow-400 py-10 lg:py-0">
        <div className="space-y-5 px-10">
          <h1 className="max-w-xl font-serif text-6xl">
            <span className="underline decoration-black decoration-4">
              Medium
            </span>{' '}
            is a place to write, read, and connect
          </h1>
          <h2>
            It's easy and free to post your thinking on any topic and connect with millions of readers
          </h2>
        </div>
        <img
          className="hidden h-32 md:inline-flex lg:h-full"
          src="http://accountabilitylab.org/wp-content/uploads/2020/03/Medium-logo.png"
          alt=""
        />
      </div>

      {/* Posts */}
      {posts.map((post) => (
        <Link key={post._id} href={`/post/${post.slug.current}`}>
          <div>
            <img src={urlFor(post.mainImage).url()!} alt="" />
            <div>
              <div>
                <p>Test 1</p>
                <p>Test 2 by Test 3</p>
              </div>
            </div>
          </div>
        </Link>
      ))}
    </div>
  )
}

When I change the part with "Test 1", "Test 2", "Test 3" to the following code, it no longer works and throws an error:

{/* Posts */}
      {posts.map((post) => (
        <Link key={post._id} href={`/post/${post.slug.current}`}>
          <div>
            <img src={urlFor(post.mainImage).url()!} alt="" />
            <div>
              <div>
                <p>{post._title}</p>
                <p>{post.description} by {post.author}</p>
              </div>
            </div>
          </div>
        </Link>
      ))}

The interface I export from typings.ts is as follows:

export interface Post {
  _id: string
  _createdAt: string
  _title: string
  author: {
    name: string
    image: string
  }
  description: string
  mainImage: {
    asset: {
      url: string
    }
  }
  slug: {
    current: string
  }
  body: [object]
}

I have done a lot of research on this issue.

Answer №1

Inserting {post.author.name} was necessary, although the reason now eludes me.

A big thank you to CRice for the assistance!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to utilize a function to manipulate the [checked] attribute of a checkbox and toggle it between true and false?

I'm trying to update the checkbox's [checked] property by calling a method, but even though the method is being called, the checkbox status doesn't change. HTML <div*ngFor="let vest_style of VEST_STYLE"> <input type="checkbox" ...

Encountering a 404 error when translating URLs in Next.js i18n?

I am developing a multilingual service utilizing next-i18next. I wanted to have some of my routes translated as well, for example: EN: /contact => default language IT: /fa/ارتباط-با-ما => second language To achieve this, I utilized tran ...

Angular 2: Issue with Component not reinitializing when query parameters change

I am currently working with Angular 2 and the latest router component to create a search functionality. Upon clicking the search button for the first time, the router navigates to the search component and retrieves data from the service. However, I have no ...

How can we display an absolutely positioned div when hovering over a card with the help of Tailwind CSS?

I am currently working on a Next.js application with Tailwind CSS. I would like to implement a feature where additional information is displayed when hovering over a product card, similar to the functionality seen on wildberries.ru. I have tried using &apo ...

Exploring the connection between a handful of documents using NextJs and Firebase

Wishing you a fantastic day! I'm a beginner with NextJs and I'm encountering an issue when trying to map my Firebase documents. I want to display 5 cards on my website, but I'm having trouble limiting the posts displayed. Here is my referen ...

What is the process for utilizing datePipe in an Angular component?

How can I implement DatePipe in my Angular component? This is the code snippet that I am currently using. for (let i = 0; i < this.days.length; i++) { this.storeStart(this.days[i], null, null, null); } I have stored weekdays (Monday to Frid ...

Creating a fresh JSON structure by utilizing an established one

I have a JSON data that contains sections and rubrics, but I only need the items for a new listing. The new object named 'items' should consist of an array of all the items. The final JSON output should be sorted by the attribute 'name&apos ...

Is there a way to turn off the "defer" feature in an Angular build?

After compiling my Angular project, I noticed that the compiler automatically adds the "defer" attribute to the script tag in my "index.html" file. However, I need to disable this feature. Is there a way to do it? I am currently working with Angular versi ...

Can you explain the distinction between "parser" and "parserOptions.parser" in an ESLint configuration?

For a considerable amount of time, I have been using the TypeScript and Vue presets provided below. While it has been functional, I realize that I do not fully comprehend each option and therefore seek to gain a better understanding. Firstly, what sets apa ...

Creating a click handler and using window.addEventListener with TypeScript in a Next.js project

I'm currently working on a click handler that should be able to detect any clicks on the window outside of my component: useEffect(() => { const handleOutSideClick = (event) => { if (!ref.current?.contains(event.target)) { se ...

Is it possible to transform a personalized typescript component into an HTMLElement within the Angular framework?

Suppose I have a customized component named 'my-component' in Angular. Is there a method to transform this component into a HTMLElement so it can be passed to a function that requires a HTMLElement as an argument? I am aware that the HTMLElemen ...

Tips for transferring i18n or t function to a dependency in next-i18next

I am faced with a situation where I have two repositories. One repository contains a nextjs application, while the second one houses components that are dynamically loaded into the first repo. Among these components in the second repository are some that ...

Implementing Facebook Javascript SDK to enable login and trigger re-authentication using React Web and Typescript within a component

As a newcomer to stack overflow, I welcome any suggestions on how I can improve my question. I'm in need of guidance concerning logging a user into facebook and requiring them to authenticate their profile or select another profile manually, rather t ...

TypeScript - the object may potentially be 'null'

Despite receiving an error message, the program is running perfectly. https://i.sstatic.net/4NQyR.jpg var video = document.querySelector('#camera-stream'), if(!navigator.getMedia){ displayErrorMessage("Your browser doesn't have su ...

Node.js server containerized with Docker: deleted express route remains accessible

I recently developed a Twitch Chat Bot using Dockerized (docker compose), Node.js v16 with express. To create an authorize-page for users to authorize my bot on the Twitch API, I utilized the route /auth/request: this.serverUrl = serverUrl; this.port = po ...

Tips for creating animations using parent and child components in Angular

Despite my best efforts, it seems like this should be functioning properly... but unfortunately it's not... I'm attempting to achieve a transition effect on the parent element (ui-switch-groove) while the child element (ui-switch-dongle) moves. ...

Is TypeScript React.SFC encountering incompatibility issues with types?

Trying to figure out TypeScript but struggling to get rid of these persistent errors. I've tried multiple approaches and resorted to using any wherever possible, but the errors still persist: (9,7): Type '(props: IRendererProps & { children? ...

The global.css base is not properly implementing the Tailwind styles

My global.css file contains some styling: @tailwind base; @tailwind components; @tailwind utilities; @layer base { .body { @apply bg-[#141414] text-white; // This should change the body color, but it's not working } } @layer componen ...

Using regular expressions to identify sentences containing a list of stopwords

In order to locate sentences that might include a series of stopwords mixed within the phrase to_match, such as: make wish make a wish make the a wish let stopword: string[]= ["of", "the", "a"]; let to_match : string = " ...

Is it feasible to utilize .NET Core as the Backend in place of Nextjs Api Routes without encountering any issues?

Currently working on an E-Commerce Website using NextJs. I'm aware that NextJS can handle both the front-end and back-end of the application. However, I'm curious about potential issues with SEO or other related factors if I were to switch from N ...