The loop works when I don't assign regionOptions to regions.data. However when I do it throws the above error. I have no idea how else to proceed any pointers would be greatly appreciated - I am very new to all of this. Many thanks!
function AddOfficeForm(props: CreateOfficeFormProps): JSX.Element | null {
let dropDownItems = [];
let regionOptions: string | any[] = [];
const region_id = uuidv4();
// TODO: fetch actual available regions from API
axios.get(ApiEndPoints.getAllRegionsForUser + firebaseContext.firebase.auth().currentUser?.uid)
.then((regions: AxiosResponse<Array<string>>) => {
regionOptions = regions.data;
})
.catch(function (error) {
console.log(error);
})
history.push("/");
const onTargetSelect = (selected: string) => {
setSelectedRegion(selected);
}
for (let i = 0; i < regionOptions.length; i++) {
dropDownItems.push(<Dropdown.Item key={regionOptions[i]} eventKey={i.toString()} onSelect={() => onTargetSelect(regionOptions[i])}>{regionOptions[i]}</Dropdown.Item>)
}