I am trying to call a function within the useEffect hook when the component first renders.
Can anyone suggest how i can do this without rewriting the function inside the useEffect function.
function reducer(currentState,newState){
return{
...currentState,
...newState
}
}
function Game() {
const [ { diceArray, locked }, setState ] = useReducer(reducer, {
diceArray: [ 1, 2, 3, 4, 5 ],
locked: [ false, false, false, false, false ]
});
useEffect(()=>{
//shuffleArray
},[])
function shuffleArray() {
const shuffledA = diceArray.map((d, i) => (locked[i] ? d : Math.ceil(Math.random() * 6)));
setState({ diceArray: shuffledA });
}
return (