I'm trying to dynamically initialize context based on a variable from within the context, the dynamic variable is an empty array of length N, where N=size which is part of the context.
I would like the default size to be 5 unless overridden in the context.
const createArray = (size) =>{
let myArray = []
for (let i=0; i<size, i++){
myArray.push(false);
}
return myArray
};
export const initialState = {
name : "",
size: 5,
slotArray : createArray(size),
}
I'm getting an error 'size' is not defined
However, if I hardcode the following it will work just fine. What am I doing wrong?
slotArray : createArray(5)
Thanks in advance