Skip to content

Commit

Permalink
perf(navbar): memoize callback function
Browse files Browse the repository at this point in the history
  • Loading branch information
bpas247 committed Aug 15, 2019
1 parent 41f32e1 commit dd0003d
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/Navbar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import classNames from 'classnames';
import React, { useMemo } from 'react';
import React, { useMemo, useCallback } from 'react';
import PropTypes from 'prop-types';

import { useUncontrolled } from 'uncontrollable';
Expand Down Expand Up @@ -145,12 +145,15 @@ const Navbar = React.forwardRef((props, ref) => {

bsPrefix = useBootstrapPrefix(bsPrefix, 'navbar');

const handleCollapse = (...args) => {
if (onSelect) onSelect(...args);
if (collapseOnSelect && expanded) {
onToggle(false);
}
};
const handleCollapse = useCallback(
(...args) => {
if (onSelect) onSelect(...args);
if (collapseOnSelect && expanded) {
onToggle(false);
}
},
[onSelect, collapseOnSelect, expanded, onToggle],
);

// will result in some false positives but that seems better
// than false negatives. strict `undefined` check allows explicit
Expand Down

0 comments on commit dd0003d

Please sign in to comment.