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:
parent
05d26a0efc
commit
6faa9eb48a
@ -19,17 +19,25 @@ class PillItem extends PureComponent {
|
|||||||
isCurrent: false,
|
isCurrent: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
this.checkIfCurrent()
|
||||||
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps) {
|
componentDidUpdate(prevProps) {
|
||||||
|
if (prevProps.location !== this.props.location) {
|
||||||
|
this.checkIfCurrent()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
checkIfCurrent() {
|
||||||
// If user navigates to different page, ensure tab bar item
|
// If user navigates to different page, ensure tab bar item
|
||||||
// with this.props.to that is on location is set to active.
|
// 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) {
|
if (this.state.isCurrent !== isCurrent) {
|
||||||
this.setState({ isCurrent })
|
this.setState({ isCurrent })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
|
@ -27,17 +27,25 @@ class TabBarItem extends PureComponent {
|
|||||||
isCurrent: false,
|
isCurrent: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
this.checkIfCurrent()
|
||||||
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps) {
|
componentDidUpdate(prevProps) {
|
||||||
|
if (prevProps.location !== this.props.location) {
|
||||||
|
this.checkIfCurrent()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
checkIfCurrent() {
|
||||||
// If user navigates to different page, ensure tab bar item
|
// If user navigates to different page, ensure tab bar item
|
||||||
// with this.props.to that is on location is set to active.
|
// 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) {
|
if (this.state.isCurrent !== isCurrent) {
|
||||||
this.setState({ isCurrent })
|
this.setState({ isCurrent })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user