From 6ea18b42fbd149a02e064ed5f0d088c1f0659430 Mon Sep 17 00:00:00 2001 From: Johan Girod Date: Thu, 18 Feb 2021 09:13:56 +0100 Subject: [PATCH] :bug: corrige le bug de la simulation vide lors du retour depuis une page de doc --- .../source/components/utils/useSimulationConfig.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mon-entreprise/source/components/utils/useSimulationConfig.ts b/mon-entreprise/source/components/utils/useSimulationConfig.ts index c4a23be20..22541866a 100644 --- a/mon-entreprise/source/components/utils/useSimulationConfig.ts +++ b/mon-entreprise/source/components/utils/useSimulationConfig.ts @@ -1,16 +1,16 @@ import { setSimulationConfig } from 'Actions/actions' -import { useEffect, useRef } from 'react' +import { useEffect } from 'react' import { useDispatch, useSelector } from 'react-redux' import { useHistory } from 'react-router' import { Company } from 'Reducers/inFranceAppReducer' import { RootState, SimulationConfig, Situation } from 'Reducers/rootReducer' +import { configSelector } from 'Selectors/simulationSelectors' export default function useSimulationConfig( config: SimulationConfig | undefined, { useExistingCompanyFromSituation = false } = {} ) { const dispatch = useDispatch() - const lastConfig = useRef() // TODO : Reading the URL here is buggy because when we do SPA navigation the // "location" retrieved at this point is still the previous URL. What we // actually need is to have a simulator identifier, which is currently not @@ -24,10 +24,10 @@ export default function useSimulationConfig( ? getCompanySituation(existingCompany) : undefined + const lastConfig = useSelector(configSelector) useEffect(() => { - if (config && lastConfig.current !== config) { + if (config && lastConfig !== config) { dispatch(setSimulationConfig(config ?? {}, url, initialSituation)) - lastConfig.current = config } }, [config, initialSituation]) }