Skip to content

Commit

Permalink
use useCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
Maigo Erit committed Aug 29, 2020
1 parent d173485 commit 95d452f
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions client/src/router.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from 'react';
import React, { useEffect, useCallback } from 'react';

import { HashRouter as Router, Route, Switch } from 'react-router-dom';
import { RootProvider } from './RootContext';
Expand All @@ -25,14 +25,17 @@ export function MainRouter() {

const [theme, setTheme] = React.useState(savedTheme || ThemeVariables[THEME_LIGHT]);

const changeActiveTheme = (event, themeName) => {
const themeVariables = ThemeVariables[themeName];
if (themeVariables) {
setTheme(themeVariables);
} else {
Logger.error('No such theme:', themeName);
}
};
const changeActiveTheme = useCallback(
(event, themeName) => {
const themeVariables = ThemeVariables[themeName];
if (themeVariables) {
setTheme(themeVariables);
} else {
Logger.error('No such theme:', themeName);
}
},
[setTheme],
);

useEffect(() => {
EventEmitter.on('activeThemeChanged', changeActiveTheme);
Expand Down

0 comments on commit 95d452f

Please sign in to comment.