Given that the state that rangeOptionChosen is one of the range options, how do I set that in typescript for useState.
const rangeOptions = [
{ label: "2 weeks", value: "2 weeks" },
{ label: "1 month", value: "1 month" },
];
const [rangeOptionChosen, setRangeOptionChosen] = useState<WhatGoesHere?>(rangeOptions[0]);
"WhatGoesHere?" should be replaced with something that says that it is "one of the elements in the array of rangeOptions"
UPDATE: I am thinking more along the lines that WhatGoesHere is strictly one of the objects of rangeOptions. I guess it would be the equivilant of something like (though I don't think this is valid typescript):
useState<
{ label: "2 weeks", value: "2 weeks" }|
{ label: "1 month", value: "1 month" }>(rangeOptions[0])
But of course be able to accommodate a much larger list based on the array, and if someone tried to do
setRangeOptionChosen({ label: "cat", value: "dog" })
it would create a typescript error because it doesn't match one of the original range options.