React Js Year Picker | Year list in dropdown
React Js Year Picker | Year list in dropdown:A React JS Year Picker is a user interface component that allows users to select a specific year from a dropdown list. It offers a convenient way to pick a year from a predefined list, typically presented in a dropdown menu format. Users can easily navigate through the years and make selections with minimal effort. This component is commonly used in web applications where a specific year input is required, such as date selection forms or filtering options. It enhances the user experience by providing a simple and intuitive method to choose a year from a list of options.




Thanks for your feedback!
Your contributions will help us to improve service.
How can I create a Year Picker in Reactjs with a dropdown that displays a list of years to choose from?
This React JS Year Picker is a simple component that allows users to select a year from a dropdown list. It uses the useState hook to manage the selectedYear state. The component generates a list of 50 years, starting from the current year and going back 50 years. When a year is selected, it updates the state and displays the selected year.
React Js Year Picker | Year list in dropdown
xxxxxxxxxx
<script type="text/babel">
// Add the import statement for useState hook
const { useState } = React;
// Define the App component
const App = () => {
const [selectedYear, setSelectedYear] = useState("");
const handleYearChange = (event) => {
setSelectedYear(event.target.value);
};
const years = Array.from(
{ length: 50 },
(_, index) => new Date().getFullYear() - index
);
return (
<div className="year-picker">
<h3>React Js Year Picker</h3>
<select value={selectedYear} onChange={handleYearChange}>
<option value="">Select a year</option>
{years.map((year) => (
<option key={year} value={year}>
{year}
</option>
))}
</select>
{selectedYear && <p>You selected: {selectedYear}</p>}
</div>
);
};
ReactDOM.render(<App />, document.getElementById("app"));
</script>