Setting the file. One moment.
Skill 03 · Vercel React Best Practices
Subchapter 3.61
rules/rerender-simple-expression-in-memo.mdMarkdown1018 BView on GitHub
When an expression is simple (few logical or arithmetical operators) and has a primitive result type (boolean, number, string), do not wrap it in . Calling and comparing hook dependencies may consume more resources than the expression itself.
useMemouseMemoIncorrect:
function Header({ user, notifications }: Props) {
const isLoading = useMemo(() => {
return user.isLoading || notifications.isLoading
}, [user.isLoading, notifications.isLoading])
if (isLoading) return <Skeleton />
// return some markup
}Correct:
function Header({ user, notifications }: Props) {
const isLoading = user.isLoading || notifications.isLoading
if (isLoading) return <Skeleton />
// return some markup
}