Can you help me figure out how to turn this table below into a filtered dropdown using reactjs. I need to filter the result by age ( let's say the user is 33 years old) and show him the available options for his age group ( Capital to cover and monthly premium related to it ) then catch the data selected.
here is what I have accomplished so far:
1 - Turn the Excel table to CSV then using this website https://shancarter.github.io/mr-data-converter/ I changed it to JSON ARRAY. Here is a snippet of the result :
[["111.000 €","25 €","27 €","28 €","31 €","34 €" ],["138.000 €","32 €","33€","35€","39 €","42 €" ].... ]
2 - calculate the Age from birthdate then connect a function to identify the category to which the user belongs to. Note what I call Index is the index of the list item ex: ["111.000 €","25 €","27 €","28 €","31 €","34 €" ] the list starts at 0 , 1, 2 ... corresponding to the column on the excel sheet.
getIndex = (age) => {
let index = null;
if (age < 25 ) {
index = 1
}
if (age < 30 && age > 24) {
index = 2
}
if (age < 40 && age > 29) {
index = 3
}
if (age < 45 && age > 39) {
index = 4
}
if (age > 45) {
index = 5
}
this.setState({
age_index : index
})
};
3- I Use forEach to get separate items from the main list and generate a new list with only the parameters matching the index value.
createNewArrayLife = (listitem) => {
if (this.state.age_index) {
listitem.forEach((item) => {
let data = {
capital: item[0],
premium: item[this.state.age_index]
};
// Something is wrong from Here! ....
this.setState({
life_insurance: [data, ...this.state.life_insurance]
});
});
}
};
This is where I am hitting a little snag for some reason the state value only shows the last item ( it's like the list is not getting populated )
Any thoughts?
