I am trying to scroll through different options that are stored in an array, by using the function below and passing it the correct parameters. But no matter what syntax I try, it doesn’t seem to work.
This is my array and the ref variable i use:
const clothingTypes = ['blazerAndShirt', 'blazerAndSweater', 'collarAndSweater', 'graphicShirt'];
const selectedClothingType = ref(clothingTypes[0]);
I have tried calling the following function in two different ways:
const nextType = (array, refVariable) => {
const currentIndex = array.indexOf(refVariable.value);
const nextIndex = (currentIndex + 1) % array.length;
refVariable.value = array[nextIndex];
};
@click="() => nextType(clothingTypes, selectedClothingType)"
and
@click="nextType(clothingTypes, selectedClothingType)"
But I get the same error in console:
Uncaught TypeError: can’t assign to property “value” on “blazerAndShirt”: not an object
What is the correct syntax?