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

The user interface design transforms as a PDF file is being generated through html2pdf

I am experiencing an unusual problem while using html2pdf to convert an HTML page to a PDF file and download it. The conversion process is successful and the PDF file is downloaded without any issues. However, when I click on a button to generate the file, ...

Developing a specialized command-line application for currency conversion is my current project

Currently, I am working on developing a command-line application for currency exchange. I have created an interface to define the structure of an object array that will store the keys and values of currency names along with their current values in the inte ...

Utilizing the input element to modify the font color of the title upon clicking the button

I've been honing my skills in Angular and facing an issue with altering the font color of a variable called title. I'm struggling to figure it out. Take a look at the code snippet from tools.component.ts: [...] title: string = 'Add note ...

Guide to specifying an explicit return type annotation for a recursive closure with JSDoc

In a project that utilizes vanilla JavaScript and type checking with tsc through JSDoc annotations, I have encountered a challenging use case. There is a function that returns another function, which may recursively call itself while also reassigning certa ...

Guide to integrating google-map-react with Next.js

I can't seem to figure out what's causing the issue. I'm attempting to utilize google-map-react in my Next.js application. I followed the example provided on their npm page almost exactly. Here is the code snippet: import React from "re ...

Encountering a CORS error while attempting to initiate a Github API call on my Next App

I'm currently developing a Next.js React app with TypeScript and I am wondering if I need a server to make requests to the GitHub API. In my next.config.mjs file, as shown below, the only task my app needs is to fetch content from a file in a public r ...

Navigating the world of Typescript: mastering union types and handling diverse attributes

I am currently working on building a function that can accept two different types of input. type InputA = { name: string content: string color: string } type InputB = { name: string content: number } type Input = InputA | InputB As I try to impleme ...

The configuration of the leaflet in Nextjs seems to be malfunctioning

I am facing an issue while trying to integrate a customizable map on my website using React Leaflet. The map appears visible, but the tiles are cut off in different sections marked as "leaflet-tiles". It's causing some display problems that ...

Encountering errors 'LeftSegment' not found and 'infer' not found within the react-router directory in the node_modules folder

Currently, I am in the process of updating my application from react-router v3 to v6. At the moment, I have successfully installed react-router-dom v6.2.1 as well as react-router v6.2. Additionally, since I am using Typescript, I have also installed @types ...

What is the best way to include multiple targets/executables within a single Node.js repository?

My React Native app is developed using TypeScript, and I want to create CLI tools for developers and 'back office' staff also in TypeScript. These tools should be part of the same monorepo. After attempting to do this by creating a subfolder wit ...

react-vimeo not firing onPause and onPlay events

I am facing an issue with triggering props when playing a Vimeo video on my webpage. Here's a snippet of my code: import Vimeo from '@u-wave/react-vimeo'; const handleVimeoProgress = (data: any) => { console.log('Progress:' ...

Versatile typing capabilities

Is it possible to have a function that takes a configuration object as its parameter, specifying which properties in a data object should be read? The configuration object has two properties that correspond to keys in the data object. The configuration ob ...

Building a custom Angular 6 pipe for generating a summary of a text snippet

Looking to create a pipe that limits the text box to only show the first 150 characters of the description. If the description is shorter than that, it should display the entire description followed by (...) Currently working on this: export class Tease ...

Angular Notification not visible

I have been attempting to display a notification after clicking a button using the angular-notifier library (version: 4.1.1). To accomplish this, I found guidance on a website called this. Despite following the instructions, the notification fails to app ...

Learn how to manipulate Lit-Element TypeScript property decorators by extracting values from index.html custom elements

I've been having some trouble trying to override a predefined property in lit-element. Using Typescript, I set the value of the property using a decorator in the custom element, but when I attempt to override it by setting a different attribute in the ...

Getting the Class name in Typescript

How can you retrieve the class name from within a Class in typescript? For instance, consider this code snippet: export class SomeRandomName extends AbstractSomething<SomeType> implements OnDestroy { className = 'SomeRandomName'; Is th ...

Value of the environmental variable not being interpreted

While exploring the world of environment variables, I encountered a puzzling issue. In my root project folder, I have two files named '.env.local' and '.env'. Strangely, the values in the '.env' file are not being processed, w ...

What is the best way to show a video on autoplay with no controls in NextJS 14?

Is there a way to display a video on autoplay without any controls in NextJS 14? I have tried to make it work, but the autoplay feature does not seem to be functioning properly. Below is the code for my component: function Hero() { return ( <di ...

What is the method for obtaining a dynamic route path within the pages directory in Next.js?

In my code, I have a special Layout component that compares routing queries and displays the appropriate layout based on the query. I'm looking to extend this functionality to handle dynamic routing scenarios, such as invoices/invoice-1. Currently, ...

What is the best way to bring in a service as a singleton class using System.js?

I have a unique Singleton-Class FooService that is loaded through a special import-map. My goal is to efficiently await its loading and then utilize it in different asynchronous functions as shown below: declare global { interface Window { System: Sy ...