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

How to Specify the Format of an Image or URL in Next.js

When using the Next.js image component, it automatically selects the most suitable format for images (avif, webm, etc.) based on the accepted format types of the browser. However, in my situation, I specifically need avif for most images but jpeg for certa ...

Troubleshooting problems with mapping over data in NextJS using react-query

I recently transitioned to using NextJS (version 13.4.12) and decided to give react-query a try for data fetching. Before adopting react-query, I had been using a custom useFetch hook that was functioning properly. To implement react-query as per recommen ...

The functionality of the `next-auth` signOut button click does not seem to accept a variable as input, although

The Nav.jsx component code provided is working as intended. In this implementation, clicking the 'Sign Out' button will redirect the application to http://localhost:3000. 'use client' import { signOut } from 'next-auth/react&apos ...

The 'Alias[]' type does not share any properties with the 'Alias' type

I encountered an issue: The error message 'Type 'Alias[]' has no properties in common with type 'Alias'' appeared. Here is my Alias setup: alias: Alias = { id: 0, domain_id: 0, source: '', dest ...

What is the best way to obtain an error as an object when subscribing to an HTTP GET request

I am working on an asp.net core webApi along with an Angular9 WebApp. My goal is to retrieve the error in a subscribe as an object rather than just a string. this.http.post<TestSystem>(this.url, testsystem).subscribe((result) => { // do someth ...

The React setState function does not refresh the user interface or initiate the useEffect function

Initially, the wrapper component has a state with two items: const initialData = { first: clubData.applications[0].invoice_url, second: clubData.applications[0].invoice_url_2, }; const [invoiceFiles, setInvoiceFiles] = useState(initialData); ...

Tips for properly waiting for an AngularFire2 subscription to complete before executing the subsequent lines of code within Angular2

Having an issue with my Angular2 Type Script code. The goal is to access Questions from a Firebase Database by subscribing to a FirebaseListObserver: this.af.list('/questions').subscribe( val => { this.questions = val console.log(th ...

Endless cycle of NGRX dispatching

I tried creating a simple ngrx project to test the store, but I encountered an infinite loop issue. Even after attempting to mimic other examples that do not have this problem. To begin with, I defined 2 class models as shown below: export interface IBookR ...

Tips on using Visual Studio Code to troubleshoot Angular 4 unit tests

I am working on an Angular 4 project with Material design in Visual Studio Code. The setup is done using angular/cli. Currently, I have been writing unit tests using Karma and Jasmine. However, when trying to debug the tests by setting breakpoints, it doe ...

Issue encountered while declaring a variable as a function in TSX

Being new to TS, I encountered an interesting issue. The first code snippet worked without any errors: interface Props { active: boolean error: any // unknown input: any // unknown onActivate: Function onKeyUp: Function onSelect: Function onU ...

The ID provided does not match the format of a Function Type

Click here for the image import {MongoClient, ObjectId} from "mongodb"; async function handler(req, res){ if(req.method === "POST"){ const data = req.body; const client = await MongoClient.connect("mongoDB URL&q ...

Invoke a custom AWS CodeBuild project in CodePipeline using a variety of parameters

Imagine having a CodePipeline with 2 stages structured like this: new codepipeline.Pipeline(this, name + "Pipeline", { pipelineName: this.projectName + "-" + name, crossAccountKeys: false, stages: [{ stageName: &apos ...

Converting hexadecimal to binary using Javascript or Typescript before writing a file on an Android or iOS device

Hey everyone! I'm facing a puzzling issue and I can't seem to figure out why it's happening. I need to download a file that is stored in hex format, so I have to first read it as hex, convert it to binary, and then write it onto an Android/ ...

Efforts to toggle visibility of icons in React

One issue I encountered is with the Navbar in mobile mode, where the icons are covering the menu. Refer to the image for a visual representation of the problem. To address this issue, my plan is to hide the icons when the hamburger icon is clicked. Below ...

When the meta tag content "&" is used, it will be converted to "&amp;" in the final output

In my Nextjs webapp, I am utilizing Firebase to store images. The URI contains the "&" sign that is being converted to "&" inside the Head component. For instance, if I create a simple tag like this <meta property="test" content="& ...

Errors during Next.js build process are proving to be elusive, as even verbose logging

After updating to the newest version of Next.js, my project runs smoothly in developer mode. However, when attempting a production build using npx next build --debug, I encounter the following error. Unfortunately, the output does not provide much insight ...

Challenges faced when using an array of objects interface in Typescript

I have initialized an array named state in my component's componentDidMount lifecycle hook as shown below: state{ array:[{a:0,b:0},{a:1,b:1},{a:2,b:2}] } However, whenever I try to access it, I encounter the following error message: Prop ...

Different ways to pass a component function's return value to a service in Angular

On my HTML page, I am presenting job details within Bootstrap panels sourced from a JSON array using an ngFor loop. Each panel showcases specific job information along with a unique job ID. The panel is equipped with a click event which triggers the execut ...

Angular 4/5 | Custom Dropdown Component

I have been working on a custom dropdown directive in Angular that I can attach to any DOM element. Below is the code for my directive: import { Directive, HostListener } from '@angular/core'; @Directive({ selector: '[appDropdown]' ...

Pages that utilize the `getServerSideProps` function cannot be exported

I seem to be a bit confused here. Based on the documentation, if I want Server Side Rendering (SSR) for the page, I need to export the async function: getServerSideProps However, when I try to build or deploy the project locally or on Zeit now, I encoun ...