I'm looking to dynamically create a new component every time the user clicks a button.
export default function WorkoutCard({ children }) {
const [workoutNum, setWorkoutNum] = useState([1]);
const addSets = () => {
setWorkoutNum(workoutNum.push(workoutNum.length + 1));
};
return (
<View style={styles.card}>
<AppText style={styles.exerciseHeader}>{children}</AppText>
{workoutNum.map((num) => (
<WorkoutTextInput workoutNum={num} />
))}
<Divider></Divider>
<Button title="Add set" style={styles.add} onPress={addSets} />
</View>
);
}
Basically, I'm trying to create an array which is also going to have the following values [1,2,3,4...] when the user clicks the button. But I'm getting the following error when I press the button - 'Undefined is not a function'.
Any tips on how I can fix this please?