diff --git a/src/ui/NavSwitcher/NavSwitcher.js b/src/ui/NavSwitcher/NavSwitcher.js index 6e527c14e..dc8c5442d 100644 --- a/src/ui/NavSwitcher/NavSwitcher.js +++ b/src/ui/NavSwitcher/NavSwitcher.js @@ -1,11 +1,16 @@ -import React from 'react' +import React, { memo } from 'react' +import PropTypes from 'prop-types' import classNames from 'classnames' +import _map from 'lodash/map' +import { isEqual } from '@bitfinex/lib-js-util-base' import { tracker } from 'utils/trackers' -import { propTypes, defaultProps } from './NavSwitcher.props' -const NavSwitcher = (props) => { - const { items, onChange, value: activeItem } = props +const NavSwitcher = ({ + items, + onChange, + value: activeItem, +}) => { const handleClick = (itemValue) => { tracker.trackEvent(itemValue, 'Tab') onChange(itemValue) @@ -13,14 +18,18 @@ const NavSwitcher = (props) => { return (
- {items.map((item) => { + {_map(items, (item) => { const { label, value: itemValue } = item const itemClasses = classNames('nav-switcher-item', { - 'nav-switcher-item--active': itemValue === activeItem, + 'nav-switcher-item--active': isEqual(itemValue, activeItem), }) return ( - handleClick(itemValue)} key={itemValue}> + handleClick(itemValue)} + > {label} ) @@ -29,7 +38,13 @@ const NavSwitcher = (props) => { ) } -NavSwitcher.propTypes = propTypes -NavSwitcher.defaultProps = defaultProps +NavSwitcher.propTypes = { + items: PropTypes.arrayOf(PropTypes.shape({ + label: PropTypes.string, + value: PropTypes.string, + })).isRequired, + onChange: PropTypes.func.isRequired, + value: PropTypes.string.isRequired, +} -export default NavSwitcher +export default memo(NavSwitcher) diff --git a/src/ui/NavSwitcher/NavSwitcher.props.js b/src/ui/NavSwitcher/NavSwitcher.props.js deleted file mode 100644 index e2bde0ea4..000000000 --- a/src/ui/NavSwitcher/NavSwitcher.props.js +++ /dev/null @@ -1,9 +0,0 @@ -import PropTypes from 'prop-types' - -export const propTypes = { - items: PropTypes.array.isRequired, - onChange: PropTypes.func.isRequired, - value: PropTypes.string.isRequired, -} - -export const defaultProps = {} diff --git a/src/ui/NavSwitcher/index.js b/src/ui/NavSwitcher/index.js index d0c747c03..3829155c0 100644 --- a/src/ui/NavSwitcher/index.js +++ b/src/ui/NavSwitcher/index.js @@ -1,3 +1 @@ -import NavSwitcher from './NavSwitcher' - -export default NavSwitcher +export { default } from './NavSwitcher'