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

[Bug]: Unexpected behavior : react/no-multi-comp #3635

Closed
raj-vc opened this issue Sep 27, 2023 · 5 comments
Closed

[Bug]: Unexpected behavior : react/no-multi-comp #3635

raj-vc opened this issue Sep 27, 2023 · 5 comments
Labels

Comments

@raj-vc
Copy link

raj-vc commented Sep 27, 2023

Is there an existing issue for this?

  • [] I have searched the existing issues and my issue is unique
  • [] My issue appears in the command-line and not only in the text editor

Description Overview

I'm using eslint-plugin-react@7,33,2 and I am getting false positive error Declare only one React component per file react/no-multi-com issue reported.

image

I've seen the same issue in #3412

Expected Behavior

It's is working using "react/no-multi-comp": ["error", { "ignoreStateless": true }] , but It should work without it

eslint-plugin-react version

v7.33.2

eslint version

v8.47.0

node version

v16.15.1

@raj-vc raj-vc added the bug label Sep 27, 2023
@raj-vc
Copy link
Author

raj-vc commented Sep 27, 2023

"use client";

import { ChevronLeft, ChevronRight } from "lucide-react";
import * as React from "react";
import { DayPicker } from "react-day-picker";

import { cn } from "@/lib/utils";
import { buttonVariants } from "../Button/Button";

export type CalendarProps = React.ComponentProps<typeof DayPicker>;

function Calendar({
  className,
  classNames,
  showOutsideDays = true,
  ...props
}: CalendarProps): JSX.Element {
  return (
    <DayPicker
      showOutsideDays={showOutsideDays}
      className={cn("p-3", className)}
      classNames={{
        months: "flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0",
        month: "space-y-4",
        caption: "flex justify-center pt-1 relative items-center",
        caption_label: "text-sm font-medium",
        nav: "space-x-1 flex items-center",
        nav_button: cn(
          buttonVariants({ variant: "outline" }),
          "h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100"
        ),
        nav_button_previous: "absolute left-1",
        nav_button_next: "absolute right-1",
        table: "w-full border-collapse space-y-1",
        head_row: "flex",
        head_cell:
          "text-slate-500 rounded-md w-9 font-normal text-[0.8rem] dark:text-slate-400",
        row: "flex w-full mt-2",
        cell: "text-center text-sm p-0 relative [&:has([aria-selected])]:bg-slate-100 first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md focus-within:relative focus-within:z-20 dark:[&:has([aria-selected])]:bg-slate-800",
        day: cn(
          buttonVariants({ variant: "ghost" }),
          "h-9 w-9 p-0 font-normal aria-selected:opacity-100"
        ),
        day_selected:
          "bg-primary text-slate-50 hover:bg-primary hover:text-slate-50 focus:bg-primary focus:text-slate-50 dark:bg-slate-50 dark:text-slate-900 dark:hover:bg-slate-50 dark:hover:text-slate-900 dark:focus:bg-slate-50 dark:focus:text-slate-900",
        day_today:
          "bg-primary/20 text-primary dark:bg-slate-800 dark:text-slate-50",
        day_outside: "text-slate-500 opacity-50 dark:text-slate-400",
        day_disabled: "text-slate-500 opacity-50 dark:text-slate-400",
        day_range_middle:
          "aria-selected:bg-slate-100 aria-selected:text-slate-900 dark:aria-selected:bg-slate-800 dark:aria-selected:text-slate-50",
        day_hidden: "invisible",
        ...classNames,
      }}
      components={{
        // eslint-disable-next-line react/no-multi-comp
        IconLeft: ({ ...props }) => <ChevronLeft className="h-4 w-4" />,
        // eslint-disable-next-line react/no-multi-comp
        IconRight: ({ ...props }) => <ChevronRight className="h-4 w-4" />,
      }}
      {...props}
    />
  );
}
Calendar.displayName = "Calendar";

export default Calendar;

@ljharb
Copy link
Member

ljharb commented Sep 27, 2023

indeed , the IconLeft and IconRight functions are components - they take props, and render jsx, and are named in PascalCase. You could try IconLeft() { return <ChevronLeft className="h-4 w-4" />; } etc?

@raj-vc
Copy link
Author

raj-vc commented Sep 27, 2023

@ljharb tried this but still getting the error

@ljharb
Copy link
Member

ljharb commented Sep 28, 2023

then i don't think there's a way to avoid it here; these are components, so you can either define them in another file or ignore the warning, as you've done.

@raj-vc
Copy link
Author

raj-vc commented Sep 28, 2023

Okay @ljharb , Thanks for Help

@raj-vc raj-vc closed this as completed Sep 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants