1
I’m using the react-select
to select the React project.
I need to return the last five years.
And then popular the options={}
select.
Only that he is only taking the last year, in the case 2020, but is not bringing the whole list, that would be: 2020,2019,2018,2017,2016
const getOptions = () => {
const years = [];
for (let i = 0; i < 5; i++) {
years.push(new Date().getFullYear() - i);
}
for (let valor of years) {
console.log(valor);
const anos = [
{
value: valor,
label: valor
}
];
console.log("years", years);
console.log("anos", anos);
return anos;
}
};
Select:
<Select
placeholder="Ano"
value={props.values.ano}
onChange={selectedOption => {
handleChange("ano")(selectedOption);
}}
isSearchable={true}
options={getOptions()}
styles={customStyles}
name="ano"
isLoading={false}
loadingMessage={() => "Carregando os ano"}
noOptionsMessage={() => "Não tem ano"}
/>
I liked the way you did, especially the imperative and declarative explanation.
– Carlos Querioz