From 7adc693ee5f3c13942ef4dc621b682c8851c4f73 Mon Sep 17 00:00:00 2001 From: Roman Edirisinghe Date: Tue, 13 Feb 2024 16:21:38 -0500 Subject: [PATCH] Resolves react warning in console See https://github.com/openedx/frontend-app-learner-dashboard/issues/291 As an aside, it's worth noting these files are practically the same, and with very little effort could be refactored into one in the spirit of DRY-ness. --- .../WidgetContainers/LoadedSidebar/index.jsx | 10 +++++++--- .../WidgetContainers/NoCoursesSidebar/index.jsx | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/containers/WidgetContainers/LoadedSidebar/index.jsx b/src/containers/WidgetContainers/LoadedSidebar/index.jsx index 8f5f2224..bd9bdec0 100644 --- a/src/containers/WidgetContainers/LoadedSidebar/index.jsx +++ b/src/containers/WidgetContainers/LoadedSidebar/index.jsx @@ -7,9 +7,14 @@ import hooks from 'widgets/ProductRecommendations/hooks'; export const WidgetSidebar = ({ setSidebarShowing }) => { const { inRecommendationsVariant, isExperimentActive } = hooks.useShowRecommendationsFooter(); - if (!inRecommendationsVariant && isExperimentActive) { - setSidebarShowing(true); + React.useEffect(() => { + if (!inRecommendationsVariant && isExperimentActive) { + setSidebarShowing(true); + } + return null; + }, [inRecommendationsVariant, isExperimentActive, setSidebarShowing]); + if (!inRecommendationsVariant && isExperimentActive) { return (
@@ -18,7 +23,6 @@ export const WidgetSidebar = ({ setSidebarShowing }) => {
); } - return null; }; diff --git a/src/containers/WidgetContainers/NoCoursesSidebar/index.jsx b/src/containers/WidgetContainers/NoCoursesSidebar/index.jsx index c3e669ad..ab137297 100644 --- a/src/containers/WidgetContainers/NoCoursesSidebar/index.jsx +++ b/src/containers/WidgetContainers/NoCoursesSidebar/index.jsx @@ -7,9 +7,14 @@ import hooks from 'widgets/ProductRecommendations/hooks'; export const WidgetSidebar = ({ setSidebarShowing }) => { const { inRecommendationsVariant, isExperimentActive } = hooks.useShowRecommendationsFooter(); - if (!inRecommendationsVariant && isExperimentActive) { - setSidebarShowing(true); + React.useEffect(() => { + if (!inRecommendationsVariant && isExperimentActive) { + setSidebarShowing(true); + } + return null; + }, [inRecommendationsVariant, isExperimentActive, setSidebarShowing]); + if (!inRecommendationsVariant && isExperimentActive) { return (
@@ -18,7 +23,6 @@ export const WidgetSidebar = ({ setSidebarShowing }) => {
); } - return null; };