I have a component in React and attached react-flatpicker to get the date value.
However, after I use useRef, it shows the value as "may be null", and yes, after console.log
, the result is the same:
<Flatpickr ref={fp} name="startTime" className="py-2 bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" options={{enableTime: true, noCalendar: true, dateFormat: "H:i",}} />
This is the function:
const fp = useRef(null); function handleSubmitAgenda() { console.log(fp?.current?.value); }
Please give me some inspiration.
To get the value from the React Flatpickr component when you click the button, you need to use the
onChange
property provided by Flatpickr.Please view the code base below.
Hope it helps you. good luck.