From a124be12fe6db22e6e3c4c04219383d5c85654ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Dudfield?= Date: Wed, 17 Jan 2024 21:50:44 +0100 Subject: [PATCH] frontend: userselectioncontext: Fix hooks so used in component Because rule of hooks. Fixes lint issue. --- frontend/app/contexts/userselectioncontext.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/frontend/app/contexts/userselectioncontext.tsx b/frontend/app/contexts/userselectioncontext.tsx index 6efc5f4b..de663dc7 100644 --- a/frontend/app/contexts/userselectioncontext.tsx +++ b/frontend/app/contexts/userselectioncontext.tsx @@ -11,6 +11,10 @@ export const CensusDispatchContext = createContext | null>(null); export default function PlotProvider({children}: { children: React.ReactNode }) { + const plotListContext = usePlotListContext(); + const censusListContext = useCensusListContext(); + const quadratListContext = useQuadratListContext(); + const [plot, plotDispatch] = useReducer( plotsReducer, null @@ -43,7 +47,6 @@ export default function PlotProvider({children}: { children: React.ReactNode }) } function plotsReducer(currentPlot: any, action: { plotKey: string | null }) { - let plotListContext = usePlotListContext(); if (plotListContext) { if (action.plotKey == null) return null; else if (plotListContext.find((p) => p.key == action.plotKey)) return plotListContext.find((p) => p.key == action.plotKey); @@ -56,7 +59,6 @@ function plotsReducer(currentPlot: any, action: { plotKey: string | null }) { } function censusReducer(currentCensus: any, action: { census: number | null }) { - let censusListContext = useCensusListContext(); if (censusListContext) { if (action.census == null) return null; else if (censusListContext.includes(action.census)) return action.census; @@ -69,7 +71,6 @@ function censusReducer(currentCensus: any, action: { census: number | null }) { } function quadratReducer(currentQuadrat: any, action: { quadrat: number | null }) { - let quadratListContext = useQuadratListContext(); if (quadratListContext) { if (action.quadrat == null) return null; else if (quadratListContext.includes(action.quadrat)) return action.quadrat;