I have a useEffect in my Routes in App.js
<Switch>
<Route exact path={['/en', '/fr']} component={HomePage} />
<Route path={['/en/*', '/fr/*']}>
<Route path="/:lang/*" component={DefaultLanguage} />
in the same file(App.js) we have the component like so (using react-localize-redux):
const DefaultLanguage = withLocalize(
({ activeLanguage, setActiveLanguage, ...props }) => {
useEffect(() => {
console.log('setting active language');
setActiveLanguage(props.match.params.lang);
}, []);
return <></>;
}
);
The problem is every link i click runs setActiveLanguage even though i put []
to make it only run on first render (because that's the only time I care about setting language from URL) I've had this issue in other parts of the app as well. From my understanding useEffect shouldn't run everytime the component is mounted unless its dependancies change, but it seems I'm missing a detail.