What steps should I follow to integrate the NextUI Tab component in my NextJS project?

Hi everyone, I am new to NextJS. I recently set up a basic NextJS starter project with NextUI by using the command

npx create-next-app -e https://github.com/nextui-org/next-app-template
.

Now, I am trying to add a tab group with 3 tabs to the default page.tsx. Following the documentation at , here is what I have so far:

...
import {Tabs, Tab} from "@nextui-org/tabs";
import {Card, CardBody} from "@nextui-org/card";
import {Chip} from "@nextui-org/chip";
...

export default function Home() {
    const tabInput = (
      <Tabs aria-label="Options">
        <Tab key="location" title="Location">
          <Card>
            <CardBody>
              <Chip>Bay Area</Chip>
              <Chip>NYC</Chip>
            </CardBody>
          </Card>  
        </Tab>
        <Tab key="date" title="Date">
          <Card>
            <CardBody>
              <Chip>Less than 24 hours</Chip>
              <Chip>Past week</Chip>
              <Chip>Past month</Chip>
            </CardBody>
          </Card>  
        </Tab>
      </Tabs>
    );

    return (
        <section className="flex flex-col items-center justify-center gap-4 py-8 md:py-10">
            <div className="inline-block max-w-lg text-center justify-center">
                {tabs}
            </div>
        </section>
    );
}

Unfortunately, when I try to start my server using npm run dev, I encounter a runtime error that says:

Unhandled Runtime Error
Error: Unknown element <[object Object]> in collection.

You can find the full stack trace here.

I have checked that all dependencies are installed using

npm i @nextui-org/<component name>
. Can someone help me figure out what's missing?

Here are the versions I am using: NextJS version: 14.1.0 NextUI version: 2.x

Answer №1

If you encounter the error message "Error: Unknown element <[object Object]> in collection," it is likely due to attempting to display a client component within a server-side rendered file. In Next.Js, all files are initially server-side rendered, which can cause compatibility issues with components such as Dropdowns, Tabs, ListBoxes, and more from NextUI.

To fix this issue, simply add "use client" at the beginning of your file.

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

Navigate to a different page in NextJS without passing any query parameters

After a successful login, I can redirect the user to the dashboard page without polluting the URI. Instead of having a cluttered URI like 'somedomain.com/v1/internal/salesman/dashboard?name=SomeName&email=someemail&uid=somenumber', I was ...

What is preventing Typescript from inferring the type when assigning the output of a method with a return type to a variable?

My reusable service has a public API with documentation and types to make client usage easier. interface Storable { setItem(key: string, value: string): any; getItem(key: string): string; removeItem(key: string): any; } @Injectable({ providedIn: & ...

Challenges faced with meta tags while integrating redux-persist into Next.js

I'm currently developing an e-commerce application using Next.js and redux. One challenge I've run into is that when I integrate redux-persist into the app, all meta tags cease to function properly. Below are snippets of the code I am working wit ...

Module `coc-tsserver` not found (error ts2307)

https://i.sstatic.net/k1MVW.png Working on a project using NeoVim with CoC for TypeScript development in a yarn-3 pnp-enabled environment. Suddenly, the editor stopped recognizing imports and started showing errors for non-existent modules (refer to the s ...

Issue with displaying tab icons in Ionic 4

After updating the versions of Angular, Cordova, and Ionic, I started experiencing an issue with the tab icons displaying partially. Specifically, when my app loads with 4 tabs, only the first and third icons are visible. However, upon touching one of the ...

Can you identify a specific portion within an array?

Apologies for the poorly titled post; summarizing my query into one sentence was challenging. I'm including the current code I have, as I believe it should be easy to understand. // Constants that define columns const columns = ["a", " ...

Validate prop must consist of one of two functional components

I am looking to ensure that a prop can only be one of two different components. Here is what I currently have: MyComponent.propTypes { propA: PropTypes.oneOfType([ PropTypes.instanceOf(ClassComponentA) PropTypes.instanceOf(ClassCompon ...

Using `it` with accessing class members

When testing whether a specific object/class is correctly wired up, I often utilize it.each to prevent writing repetitive tests. The issue arises when the type of the object doesn't have an index signature, requiring me to cast it to any for it to fun ...

Tips for converting the iterator from a v-for to a string within a v-if

I am seeking to comprehend how to utilize v-for with v-if's in order to generate repeated teasers without resorting to more simplistic vue-logic. Currently, it appears that when using v-for with v-if nested within, it is not feasible to assign the ind ...

Struggle with Loading Custom Templates in Text Editor (TinyMCE) using Angular Resolver

My goal is to incorporate dynamic templates into my tinyMCE setup before it loads, allowing users to save and use their own templates within the editor. I have attempted to achieve this by using a resolver, but encountered issues with the editor not loadin ...

Accessing an Excel file in TypeScript using the .xlsx format

After extensive research, I managed to find a solution for reading the .xlsx file in a TypeScript environment. Once implemented, I documented the solution along with a question and answer. The file "demo.xlsx" contains UserIds and Code, displayed in the i ...

Next.js requires specifying explicit dimensions for local images

After reviewing their documentation, I discovered that when using a local image (e.g. from the public/ folder), specifying the width and height of an image is not necessary. Here is an example of how my setup is configured: import Image from 'next/Ima ...

Guide to fetching external data with Next.js and importing the component into a different file

I have implemented the following code in my pages/github file, and when I navigate to localhost:3000/github, the code runs successfully and returns JSON data. function GithubAPI(props) { // Display posts... return (<div>{props.data.name}</div& ...

nextJS custom theme for new directory

There seems to be a slight problem that I am facing. I understand that I can utilize _document.js for the /page, but I require a distinct document layout for a specific directory. My query is how can I alter the document theme/layout based on a subdirector ...

What steps should I take to retrieve my information from a typescript callback function?

While I am familiar with using callbacks in JavaScript, I have recently started learning Angular and TypeScript. I am facing an issue with getting my data from a service back to where I need it after executing the callback function. The callback itself i ...

Steps for generating an instance of a concrete class using a static method within an abstract class

Trying to instantiate a concrete class from a static method of an abstract class is resulting in the following error: Uncaught TypeError: Object prototype may only be an Object or null: undefined This error occurs on this line in ConcreteClass.js: re ...

Steps for creating a TypeScript project for exporting purposes

Forgive me for my lack of experience in the js ecosystem. Transitioning from static languages to typescript has been a positive change, though I still find myself struggling to grasp the packaging/module system, especially when coupled with typescript defi ...

Ways to set a button as default clicked in an Array

I have a collection that stores languages and their boolean values. My goal is to automatically set buttons to be clicked (active) for each language with a true value in the collection. Whenever a different language is selected by clicking on its respect ...

Building AngularJS directives using CSS classes

My current approach is as follows: class AService { $http: any; $state: any; static $inject = ['$http', '$state']; constructor($http, $state) { this.$http = $http; this.$state = $state; }; Dealing w ...

Using an external npm module in TypeScript can result in the tsc output directory being modified

In my TypeScript project, I have set up the build process to generate JavaScript files in the ./src/ directory. Everything works smoothly when building against existing npm modules, such as Angular 2 imports. However, I encountered a strange issue when I ...