From 0fd7146f3bea69f946f4bc9275757bcd6ca242be Mon Sep 17 00:00:00 2001 From: Aaron McAdam Date: Mon, 5 Aug 2024 21:45:55 +0100 Subject: [PATCH] add custom arePropsEqual function to useMemo --- src/components/quiz-option.tsx | 93 +++++++++++++++++++--------------- 1 file changed, 51 insertions(+), 42 deletions(-) diff --git a/src/components/quiz-option.tsx b/src/components/quiz-option.tsx index ced25cc..c626cd1 100644 --- a/src/components/quiz-option.tsx +++ b/src/components/quiz-option.tsx @@ -10,46 +10,55 @@ export type QuizOptionProps = { value: string | boolean; }; -export const QuizOption = React.memo(function QuizOption({ - onClick, - isSelected, - display, - value, -}: QuizOptionProps) { - const type = display === "Yes" || display === "No" ? "boolean" : "image"; +export const QuizOption = React.memo( + function QuizOption({ + onClick, + isSelected, + display, + value, + }: QuizOptionProps) { + const type = display === "Yes" || display === "No" ? "boolean" : "image"; - return ( - - ); -}); + return ( + + ); + }, + (prevProps, nextProps) => { + const arePropsEqual = + prevProps.isSelected === nextProps.isSelected && + prevProps.display === nextProps.display; + + return arePropsEqual; + }, +);