Unable to retrieve selected value from Flowbite-React Datepicker due to malfunctioning props change event

I am encountering an issue with extracting the selected value from the Datepicker component in the flowbite-react library while using it with NextJS.
The component is being displayed correctly.
I attempted the code below, but it does not return anything when a date is chosen:

import { Datepicker } from "flowbite-react";

export default function ExampleComp(){
 return (
   <Datepicker
       onChange={(e) => console.log(e)} // not functioning
       onSelect={(e) => console.log(e)} // not working
       onInput={(e) => console.log(e)} // not working
       onSelectedDateChanged={(e) => console.log(e)} // Error: Does not exist on type 'IntrinsicAttributes & DatepickerProps'
      />
  )
}


There isn't a specific use case mentioned in the official documentation page, but in the storybook, the prop onSelectedDateChanged exists. I have implemented it, however, I'm encountering the error:

Error: Does not exist on type 'IntrinsicAttributes & DatepickerProps'
.
Your assistance would be greatly appreciated.

Version

  • "flowbite": "^1.8.1",
  • "flowbite-react": "^0.6.0",
  • "tailwindcss": "3.3.3",
  • "next": "13.4.19"

Answer №1

After implementing onSelectedDateChanged and passing a function to the props, I successfully obtained the desired output by utilizing it with react hooks like this:

<Controller name="date"
            control={control}
            rules={{ required: 'Date is required' }}
            render=
            {({ field }) => (
             <Datepicker
              value={field.value}
              onSelectedDateChanged={(date) => field.onChange(date)}
              dateFormat="yyyy-MM-dd"
              className="border rounded px-4 py-2 w-full" />
            )}
          /> 

To use it regularly, you can employ useState to update the date in this manner:


  const handleDatePickerChange = (date) => {
    setSelectedDate(date);
    console.log(date);
  };

<Datepicker name="selectedDate" value={selectedDate}
            onSelectedDateChanged={handleDatePickerChange} /> 

Answer №2

Sorry for the delay, but this might come in handy.

function updateSelectedDate(date) {
   console.log(date);
};

<DatePicker id="selectedDate" onDateChange={updateSelectedDate}/>
            

This should do the trick.

Answer №3

function updateSelectedDate(date) {
    console.log("Selected date: " + date);
}
<DatePicker onDateSelect={updateSelectedDate}/>

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

What is the best approach to defining a type for a subclass (such as React.Component) in typescript?

Can someone help me with writing a type definition for react-highlight (class Highlightable)? I want to extend Highlightable and add custom functionality. The original Highlightable JS-class is a subclass of React.Component, so all the methods of React.Com ...

In a production environment, Nextjs lacks minification

I've been feeling a bit overwhelmed because I've been reading everywhere that Next.js minifies JavaScript (and possibly SCSS/CSS) files, but for the life of me, I can't seem to see my file minified. Let me share my "next.config.js" file wit ...

Issue with Typescript Application not navigating into the node_modules directory

After attempting to load the app from the root directory of our server, it became clear that this was not a practical solution due to the way our application uses pretty URLs. For instance, trying to access a page with a URL like http://www.website.com/mod ...

Utilizing PrimeNG's p-dataView feature without repetitive FieldSets

Currently, I am utilizing p-dataView and I'm interested in implementing p-fieldset based on the application type. My goal is to prevent the fieldset from being duplicated when multiple instances occur. The scenario below illustrates one such case; how ...

Is there a way to incorporate personalized image placeholders into Next.js?

The Image component has properties called placeholder and blurDataURL. The placeholder property can have a value of either 'blur' or 'empty', with no other option. I tried setting the placeholder to 'blur' and specifying the b ...

How can I inform Typescript that an interface will exclusively consist of defined members?

My interface looks like this interface Person { name?:string; age? :number; gender?:string } I need to reuse the same interface type, but with a modification indicating that all members will never be undefined. The updated version would look like this: ...

Issue with Material UI causing slow compilation in Next.js version 13

When trying to integrate Material UI with Next.js 13 (App router), I noticed that the compilation time during development is significantly slow. Is there a way to optimize this and decrease the compiling time? Experiencing slow compilation when using Mate ...

What advantages does using an RxJS Subject have over handling multiple event listeners individually in terms of speed

After investigating a page's slow performance, I identified an angular directive as the root cause. The culprit was a piece of code that registered event listeners on the window keydown event multiple times: @HostListener('window:keydown', ...

Converting an integer into a String Enum in TypeScript can result in an undefined value being returned

Issue with Mapping Integer to Enum in TypeScript export enum MyEnum { Unknown = 'Unknown', SomeValue = 'SomeValue', SomeOtherValue = 'SomeOtherValue', } Recently, I encountered a problem with mapping integer val ...

Creating adaptable rows and columns with Angular Material's data table feature

My approach to rendering dynamic rows and columns using a basic table was successful: <tbody> <tr *ngFor="let row of data"> <td *ngFor="let val of row"> {{ val }} </td> </tr> </tbody> </ ...

How can we update the form builder or form group in Angular 2 when making changes to the existing data in a table? I'm a bit confused on how to implement router

<tr *ngFor="let row of categories "> <td>{{row.categoryName}}</td> <td>{{row.visible}}</td> <td>{{row.instanceNumber}}</td> <td> <a class="btn btn-info btn-fill " [routerLink]="['/con ...

Error: Unable to access 'clientModules' property as it is undefined

When running the project using npm run dev, everything works fine. However, I encountered errors when deploying with vercel --prod after generating a production build and starting the app with next start. Initially, I received a TypeError: Cannot read pro ...

The access to the HTTP response object is not possible: the property is not found on the Object type

I recently created a response object and assigned it to the "this" object. However, when I try to access the datacentersinfo property, I encounter an error stating that the property does not exist on type Object. Due to this issue, I am unable to generat ...

Deploy NextJs on an IIS server

Greetings! I have a colleague who has a node.js (next.js) website that runs smoothly when built and started through the console (npm run build and npm start). We have now hosted it on an Azure VM (Windows Server 2016 IIS, with iisnode and urlrewrite inst ...

JavaScript functions are not being triggered when the submit button is clicked

I am facing an issue where the form buttons are not triggering functions in my React application. The post request is being made using Axios. Could this be related to the structure of my components? Or perhaps it has something to do with file naming conven ...

ngOnChanges will not be triggered if a property is set directly

I utilized the modal feature from ng-bootstrap library Within my parent component, I utilized modalService to trigger the modal, and data was passed to the modal using componentInstance. In the modal component, I attempted to retrieve the sent data using ...

There seems to be an issue with my React application that was built using Webpack 5 and compiled with TypeScript. The @tailwind directive is not functioning properly in the browser, and

As I embark on creating a fresh react application using Webpack 5, Tailwind CSS, and Typescript, I find myself at a crossroads. Despite piecing together various tutorials, I am struggling to configure the postcss-loader for Tailwind. While traditional .css ...

Error: Unable to locate module: Could not find 'react-server-dom-webpack/client.edge'

I've been trying to incorporate server components into my nextJS project, but I keep encountering an issue when using "use server" in my component. Error message: `./node_modules/next/dist/build/webpack/loaders/next-flight-loader/action-client-wrappe ...

Encountered an error while trying to load next.config.js - Specifically, a TypeError: The options

Need Help! I encountered an issue while trying to run my nextapp with antd design. It's giving me an error about needing a less loader, so I checked out this https://github.com/SolidZORO/next-plugin-antd-less and also this https://github.com/elado/ne ...

Zero-length in Nightmare.js screenshot buffer: an eerie sight

I'm currently working on a nightmare.js script that aims to capture screenshots of multiple elements on a given web page. The initial element is successfully captured, but any subsequent elements below the visible viewport are being captured with a l ...