|
const randomise = array => { |
|
array.sort(() => Math.random() - 0.5); |
|
}; |
This function doesn't rely on any variables in its enclosing scope, so could be defined outside the component, which makes rendering more performant. Not a big deal for a small app, but good to know going forward.
If you did have a function that referenced variables in the enclosing scope (e.g. index), you can either make the function accept additional parameters or use useCallback which memoises functions defined within the component.
ReactWeek-Martha-Georgia/src/components/QuizQuesAns.js
Lines 23 to 25 in b9507cf
This function doesn't rely on any variables in its enclosing scope, so could be defined outside the component, which makes rendering more performant. Not a big deal for a small app, but good to know going forward.
If you did have a function that referenced variables in the enclosing scope (e.g.
index), you can either make the function accept additional parameters or useuseCallbackwhich memoises functions defined within the component.