日期选择器 - Next.js

DatePicker - Next.js

提问人:Francisco 提问时间:10/2/2023 更新时间:10/2/2023 访问量:39

问:

我是使用 next.js 的新手,遇到了一个问题。我的目标是从日期选择器中检索信息,并使用它来从 Supabase 获取数据。获取的数据将取决于用户的选择。

但是,我目前面临一个问题,即我无法选择用户的日期并在服务器端渲染页面上搜索用户。

Supabase代码:

//get all tickets from supabase
const { data } = await supabase.from('tickets').select('*')

日期选择器:

 <div className="flex items-center space-x-2">
     <DatePickerWithRange />
 </div>

date-range-picker.tsx:

"use client"
export function DatePickerWithRange({
  className,
}: React.HTMLAttributes<HTMLDivElement>) {
  const [date, setDate] = React.useState<DateRange | undefined>({
    from: new Date(),
    to: subDays(new Date(), 20),
  })

  return (
    <div className={cn("grid gap-2", className)}>
      <Popover>
        <PopoverTrigger asChild>
          <Button
            id="date"
            variant={"outline"}
            className={cn(
              "w-[300px] justify-start text-left font-normal",
              !date && "text-muted-foreground"
            )}
          >
            <CalendarIcon className="mr-2 h-4 w-4" />
            {date?.from ? (
              date.to ? (
                <>
                  {format(date.from, "LLL dd, y")} -{" "}
                  {format(date.to, "LLL dd, y")}
                </>
              ) : (
                format(date.from, "LLL dd, y")
              )
            ) : (
              <span>Pick a date</span>
            )}
          </Button>
        </PopoverTrigger>
        <PopoverContent className="w-auto p-0" align="start">
          <Calendar
            initialFocus
            mode="range"
            defaultMonth={date?.from}
            selected={date}
            onSelect={setDate}
            numberOfMonths={1}
          />
        </PopoverContent>
      </Popover>
    </div>
  )
}

任何你能帮助我的事情都将受到欢迎

下一个.js 服务器端渲染 客户端 supabase

评论


答: 暂无答案