Hot reload pour les règles publicodes
parent
d1d96dad29
commit
42f89c6c7e
|
@ -15,6 +15,7 @@ import { StrictMode, useContext, useMemo } from 'react'
|
|||
import { Helmet } from 'react-helmet-async'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useSelector } from 'react-redux'
|
||||
import rules from 'modele-social'
|
||||
import { Redirect, Route, Switch } from 'react-router-dom'
|
||||
import {
|
||||
configSituationSelector,
|
||||
|
@ -46,13 +47,25 @@ import { setupSimulationPersistence } from './storage/persistSimulation'
|
|||
|
||||
type RootProps = {
|
||||
basename: ProviderProps['basename']
|
||||
rules: Rules
|
||||
rulesPreTransform?: (rules: Rules) => Rules
|
||||
}
|
||||
|
||||
export default function Root({ basename, rules }: RootProps) {
|
||||
export default function Root({
|
||||
basename,
|
||||
rulesPreTransform = (r) => r,
|
||||
}: RootProps) {
|
||||
const { language } = useTranslation().i18n
|
||||
const paths = constructLocalizedSitePath(language as 'fr' | 'en')
|
||||
const engine = useMemo(() => engineFactory(rules), [rules])
|
||||
const engine = useMemo(
|
||||
() => engineFactory(rulesPreTransform(rules)),
|
||||
|
||||
// We need to keep [rules] in the dependency list for hot reload of the rules
|
||||
// in dev mode, even if ESLint think it is unnecessary since `rules` isn't
|
||||
// defined in the component scope.
|
||||
//
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[rules]
|
||||
)
|
||||
return (
|
||||
<StrictMode>
|
||||
<Provider
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { I18nProvider } from '@react-aria/i18n'
|
||||
import rules from 'modele-social'
|
||||
import { render } from 'react-dom'
|
||||
import 'regenerator-runtime/runtime'
|
||||
import App from './App'
|
||||
|
@ -13,7 +12,9 @@ export const AppEn = () => (
|
|||
<I18nProvider locale="en-GB">
|
||||
<App
|
||||
basename="infrance"
|
||||
rules={translateRules('en', ruleTranslations, rules)}
|
||||
rulesPreTransform={(rules) =>
|
||||
translateRules('en', ruleTranslations, rules)
|
||||
}
|
||||
/>
|
||||
</I18nProvider>
|
||||
)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { I18nProvider } from '@react-aria/i18n'
|
||||
import rules from 'modele-social'
|
||||
import { render } from 'react-dom'
|
||||
import 'regenerator-runtime/runtime'
|
||||
import App from './App'
|
||||
|
@ -8,7 +7,7 @@ import './sentry'
|
|||
|
||||
export const AppFr = () => (
|
||||
<I18nProvider locale="fr-FR">
|
||||
<App basename="mon-entreprise" rules={rules} />
|
||||
<App basename="mon-entreprise" />
|
||||
</I18nProvider>
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue