Skip to content

Instantly share code, notes, and snippets.

@cjweigle
Last active August 29, 2022 10:21
Show Gist options
  • Save cjweigle/c7bf3b5a7ad21dbbb5110236439ad4f6 to your computer and use it in GitHub Desktop.
Save cjweigle/c7bf3b5a7ad21dbbb5110236439ad4f6 to your computer and use it in GitHub Desktop.
OnsenUI Tabbar Issue with React
import React from 'react';
import {Tabbar as _Tabbar} from 'react-onsenui';
class Tabbar extends React.Component{
constructor(props){
super(props);
this.render = this.render.bind(this);
this.componentWillReceiveProps = this.componentWillReceiveProps.bind(this);
this.updateIndex = this.updateIndex.bind(this);
this.state = {
index: props.index ? props.index : 0
}
}
updateIndex(e){
this.setState((s,p)=>{
return Object.assign({},s,{
index:e.index
});
});
if(this.props.onPostChange)
{
this.props.onPostChange(e);
}
}
componentWillReceiveProps(nextProps) {
if (nextProps.index !== this.props.index ) {
this.setState((s,p)=>{
return Object.assign({},s,{
index:nextProps.index
});
});
}
}
render(){
const useProps = Object.assign({},this.props,{
onPostChange:this.updateIndex,
index: this.state.index
});
return <_Tabbar {...useProps}>
{this.props.children}
</_Tabbar>;
}
}
Tabbar.displayName = 'Tabbar';
export default Tabbar;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment