🐛🎨 Répare le flickering au premier rendu des simulateurs

pull/1618/head
Johan Girod 2021-06-08 10:32:41 +02:00
parent f79d209c5a
commit 82e9f18b0e
1 changed files with 9 additions and 7 deletions

View File

@ -8,6 +8,7 @@ import {
useCallback,
useContext,
useEffect,
useMemo,
useState,
} from 'react'
import { useDispatch, useSelector } from 'react-redux'
@ -32,7 +33,10 @@ export function SimulationGoals({
className = '',
children,
}: SimulationGoalsProps) {
const initialRender = useInitialRender()
const [initialRender, setInitialRender] = useState(true)
useEffect(() => {
setInitialRender(false)
}, [])
return (
<InitialRenderContext.Provider value={initialRender}>
@ -49,11 +53,9 @@ export function SimulationGoals({
}
function useInitialRender() {
const [initialRender, setInitialRender] = useState(true)
useEffect(() => {
setInitialRender(false)
}, [])
return initialRender
const initialRender = useContext(InitialRenderContext)
const unChangedInitialRender = useMemo(() => initialRender, [])
return unChangedInitialRender
}
type SimulationGoalProps = {
@ -90,7 +92,7 @@ export function SimulationGoal({
...(!boolean ? { unité: currentUnit, arrondi: 'oui' } : {}),
})
const rule = engine.getRule(dottedName)
const initialRender = useContext(InitialRenderContext)
const initialRender = useInitialRender()
const [isFocused, setFocused] = useState(false)
const isFirstStepCompleted = useSelector(firstStepCompletedSelector)
const onChange = useCallback(