You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is more of an optimisation (your code is totally fine as is), but I think it's a cool thing to learn. useState can actually take a function that it will run to get the initial state value: https://reactjs.org/docs/hooks-reference.html#lazy-initial-state
This lets you "lazily" initialise state, which means only running the initialisation code once, rather than on every render. E.g. your code right now has to run a bunch of for loops and build up an array every time the snake moves, even though the initialArray is only used on the very first render, to initialise the state.
The text was updated successfully, but these errors were encountered:
Week10TT/src/components/snakegrid.js
Lines 10 to 26 in 91f8cac
This is more of an optimisation (your code is totally fine as is), but I think it's a cool thing to learn.
useState
can actually take a function that it will run to get the initial state value: https://reactjs.org/docs/hooks-reference.html#lazy-initial-stateThis lets you "lazily" initialise state, which means only running the initialisation code once, rather than on every render. E.g. your code right now has to run a bunch of for loops and build up an array every time the snake moves, even though the
initialArray
is only used on the very first render, to initialise the state.The text was updated successfully, but these errors were encountered: