Skip to content

Commit

Permalink
[core] Fix useLayoutEffect warnings on the server
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Apr 23, 2019
1 parent 387b79e commit 595779a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/material-ui/src/ListItem/ListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ export const styles = theme => ({
selected: {},
});

const useEnhancedEffect = typeof window === 'undefined' ? React.useEffect : React.useLayoutEffect;

/**
* Uses an additional container component if `ListItemSecondaryAction` is the last child.
*/
Expand Down Expand Up @@ -111,7 +113,7 @@ const ListItem = React.forwardRef(function ListItem(props, ref) {
alignItems,
};
const listItemRef = React.useRef();
React.useLayoutEffect(() => {
useEnhancedEffect(() => {
if (autoFocus) {
if (listItemRef.current) {
listItemRef.current.focus();
Expand Down
4 changes: 3 additions & 1 deletion packages/material-ui/src/MenuList/MenuList.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ function moveFocus(list, currentFocus, disableListWrap, traversalFunction) {
}
}

const useEnhancedEffect = typeof window === 'undefined' ? React.useEffect : React.useLayoutEffect;

const MenuList = React.forwardRef(function MenuList(props, ref) {
const { actions, autoFocus, className, onKeyDown, disableListWrap, ...other } = props;
const listRef = React.useRef();

React.useLayoutEffect(() => {
useEnhancedEffect(() => {
if (autoFocus) {
listRef.current.focus();
}
Expand Down

0 comments on commit 595779a

Please sign in to comment.