The following is the code that generates a series of buttons. As the initial render takes place a function determines whether the element has a prop called init. If it does that it performs the action as if that button had been clicked.
Technically this code works but it triggers a warning as it is effective triggering a re-render in the middle of a render. How do you trigger an effective OnRender functions?
export class NavTabItem extends React.Component {
constructor(props) {
super(props);
global.register(this, 'screen')
}
NavTabAction = () => {
global.setState({
screen: this.props.screen,
})
}
render() {
// determine whether the element has the prop of init and if it does click on it.
if(this.props.init){
this.NavTabAction()
}
return (
<TouchableOpacity onPress={this.NavTabAction}>
<View style={global.state.screen == this.props.screen ? [styles.NavTabItem, styles.NavTabItemSelected] : styles.NavTabItem}>
<View style={styles.NavTabIcon} />
<TextCap11 style={styles.NavTabLabel}>{this.props.children}</TextCap11>
</View>
</TouchableOpacity>
);
}
}