File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed
Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change 11import classNames from 'classnames' ;
2- import React from 'react' ;
2+ import React , { useMemo } from 'react' ;
33import PropTypes from 'prop-types' ;
44
55import { useUncontrolled } from 'uncontrollable' ;
@@ -152,10 +152,6 @@ const Navbar = React.forwardRef((props, ref) => {
152152 }
153153 } ;
154154
155- const handleToggle = ( ) => {
156- onToggle ( ! expanded ) ;
157- } ;
158-
159155 // will result in some false positives but that seems better
160156 // than false negatives. strict `undefined` check allows explicit
161157 // "nulling" of the role if the user really doesn't want one
@@ -165,8 +161,17 @@ const Navbar = React.forwardRef((props, ref) => {
165161 let expandClass = `${ bsPrefix } -expand` ;
166162 if ( typeof expand === 'string' ) expandClass = `${ expandClass } -${ expand } ` ;
167163
164+ const navbarContext = useMemo (
165+ ( ) => ( {
166+ handleToggle : ( ) => onToggle ( ! expanded ) ,
167+ bsPrefix,
168+ expanded,
169+ } ) ,
170+ [ bsPrefix , expanded , onToggle ] ,
171+ ) ;
172+
168173 return (
169- < NavbarContext . Provider value = { { handleToggle , bsPrefix , expanded } } >
174+ < NavbarContext . Provider value = { navbarContext } >
170175 < SelectableContext . Provider value = { handleCollapse } >
171176 < Component
172177 ref = { ref }
You can’t perform that action at this time.
0 commit comments