Updated PillItem, TabBarItem to check if isCurrent on component mount, update

• Updated:
- PillItem, TabBarItem to check if isCurrent on component mount, update
This commit is contained in:
mgabdev 2020-07-24 20:18:07 -05:00
parent 05d26a0efc
commit 6faa9eb48a
2 changed files with 26 additions and 10 deletions

View File

@ -19,15 +19,23 @@ class PillItem extends PureComponent {
isCurrent: false,
}
componentDidMount() {
this.checkIfCurrent()
}
componentDidUpdate(prevProps) {
if (prevProps.location !== this.props.location) {
this.checkIfCurrent()
}
}
checkIfCurrent() {
// If user navigates to different page, ensure tab bar item
// with this.props.to that is on location is set to active.
if (this.props.location !== prevProps.location) {
const isCurrent = this.props.to === this.props.location.pathname && !this.props.location.search
const isCurrent = this.props.to === this.props.location.pathname && !this.props.location.search
if (this.state.isCurrent !== isCurrent) {
this.setState({ isCurrent })
}
if (this.state.isCurrent !== isCurrent) {
this.setState({ isCurrent })
}
}

View File

@ -27,15 +27,23 @@ class TabBarItem extends PureComponent {
isCurrent: false,
}
componentDidMount() {
this.checkIfCurrent()
}
componentDidUpdate(prevProps) {
if (prevProps.location !== this.props.location) {
this.checkIfCurrent()
}
}
checkIfCurrent() {
// If user navigates to different page, ensure tab bar item
// with this.props.to that is on location is set to active.
if (this.props.location !== prevProps.location) {
const isCurrent = this.props.to === this.props.location.pathname && !this.props.location.search
const isCurrent = this.props.to === this.props.location.pathname && !this.props.location.search
if (this.state.isCurrent !== isCurrent) {
this.setState({ isCurrent })
}
if (this.state.isCurrent !== isCurrent) {
this.setState({ isCurrent })
}
}