nextui-org / nextui

🚀 Beautiful, fast and modern React UI library.
https://nextui.org
MIT License
22.14k stars 1.56k forks source link

[BUG] - Uncaught TypeError: type.getCollectionNode is not a function when using `DropdownSection` in NextUI with a custom component #3727

Open anandhibare opened 2 months ago

anandhibare commented 2 months ago

NextUI Version

2.4.6

Describe the bug

I'm new to React and am using the NextUI library for my project. I want to create a custom function component, ProfDropdownItem, to render multiple DropdownSection components within a DropdownMenu. However, I'm encountering an error:

Uncaught TypeError: type.getCollectionNode is not a function

Here’s the code that is causing the issue:

import React from 'react';
import { Dropdown, DropdownTrigger, DropdownMenu, DropdownSection, DropdownItem, Avatar } from '@nextui-org/react';

const ProfDropdownItem = () => {
  return (
    <DropdownSection title="Actions" showDivider>
      <DropdownItem key="new" shortcut="⌘N" description="Create a new file">
        New file
      </DropdownItem>
      <DropdownItem key="copy" shortcut="⌘C" description="Copy the file link">
        Copy link
      </DropdownItem>
      <DropdownItem
        key="edit"
        shortcut="⌘⇧E"
        description="Allows you to edit the file"
      >
        Edit file
      </DropdownItem>
    </DropdownSection>
  );
};

const SetDropdownItem = () => {
  return (
    <DropdownSection title="Settings" showDivider>
      <DropdownItem
        key="preferences"
        shortcut="⌘P"
        description="Open the preferences"
      >
        Preferences
      </DropdownItem>
      <DropdownItem key="Theme" shortcut="⌘T" description="Change the theme">
        Theme
      </DropdownItem>
      <DropdownItem
        key="privacy"
        shortcut="⌘⇧W"
        description="Privacy settings"
      >
        Privacy
      </DropdownItem>
    </DropdownSection>
  );
};

const TopBar = () => {
  return (
    <Dropdown placement="bottom-end">
      <DropdownTrigger>
        <Avatar
          isBordered
          as="button"
          className="transition-transform"
          color="secondary"
          name="User Name"
          size="sm"
          src="profilePhotoURL"
        />
      </DropdownTrigger>
      <DropdownMenu aria-label="Profile Actions" variant="flat">
        <ProfDropdownItem />
        <SetDropdownItem />
        {/* There are more sections to add dynamically ..*/}

      </DropdownMenu>
    </Dropdown>
  );
};

export default TopBar;

Your Example Website or App

No response

Steps to Reproduce the Bug or Issue

  1. Create a React project using Vite.
  2. Install NextUI and Tailwind.
  3. Ensure all components (DropdownSection, DropdownItem, DropdownMenu, DropdownTrigger, Dropdown) are imported correctly from @nextui-org/react.
  4. Run the code, and the error occurs.

Dependencies:

  1. @nextui-org/react": "^2.4.6",
  2. framer-motion: "^11.3.31",
  3. react: "^18.3.1",
  4. react-dom: "^18.3.1",
  5. use-dark-mode: "^2.3.1"

Expected behavior

The sections should be rendered inside the DropdownMenu dynamically if I wish to use some conditional logic to get a customized dropdown for a specific user.

Screenshots or Videos

image

Operating System Version

Ubuntu 24.04 LTS on WSL

Browser

Chrome

linear[bot] commented 2 months ago

ENG-1325 [BUG] - Uncaught TypeError: type.getCollectionNode is not a function when using `DropdownSection` in NextUI with a custom component

wingkwong commented 2 months ago

may revisit this issue after bumping latest RA

xuanduynguyen96 commented 1 month ago

Is there any update on this issue? I'm facing a similar issue when using ListBox.

wingkwong commented 1 month ago

@xuanduynguyen96 RA version bump will be scheduled in 2.5.0