From 79631cbc0593041f50ca204d348df99994a024b2 Mon Sep 17 00:00:00 2001 From: Tyler Hallada Date: Sat, 19 Mar 2022 15:38:33 -0400 Subject: [PATCH] Fix react warnings --- components/ModData.tsx | 8 +++++--- components/PluginsList.tsx | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/components/ModData.tsx b/components/ModData.tsx index 32326a2..ea065a3 100644 --- a/components/ModData.tsx +++ b/components/ModData.tsx @@ -1,6 +1,6 @@ import { format } from "date-fns"; import Head from "next/head"; -import React from "react"; +import React, { useEffect } from "react"; import useSWRImmutable from "swr/immutable"; import CellList from "./CellList"; @@ -50,6 +50,10 @@ const ModData: React.FC = ({ (_) => jsonFetcher(_) ); + useEffect(() => { + if (data) setSelectedCells(data.cells); + }, [data, setSelectedCells]); + if (error && error.status === 404) { return
Mod could not be found.
; } else if (error) { @@ -66,8 +70,6 @@ const ModData: React.FC = ({ const unique_downloads = modCounts ? modCounts[1] : 0; const views = modCounts ? modCounts[2] : 0; - setSelectedCells(data.cells); - if (selectedMod && data) { return ( <> diff --git a/components/PluginsList.tsx b/components/PluginsList.tsx index 79ff84b..2ab3862 100644 --- a/components/PluginsList.tsx +++ b/components/PluginsList.tsx @@ -58,7 +58,8 @@ const PluginsList: React.FC = ({ selectedCell }) => { disabled={ excludedPlugins.includes(plugin.filename) || !!plugin.parseError } - checked={plugin.enabled} + checked={plugin.enabled ?? false} + value={plugin.enabled ? "on" : "off"} onChange={() => dispatch(togglePlugin(plugin.filename))} />