Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native View Render

how can I render views conditionally? Example: if my app has not connected to internet - render error view, if connected - render WebView? Does that possible with react native? I want to render not pure html

like image 535
IntoTheDeep Avatar asked Mar 18 '16 12:03

IntoTheDeep


2 Answers

Logic to render views conditionally, using your example:

render() {
  if (!this.state.isConnected) { // error
    return (
      <View></View>
    );
  }
  else {
    return ( // webview
      <WebView />
    );
  }
}
like image 115
Josh Buchea Avatar answered Sep 28 '22 07:09

Josh Buchea


In your render method , you can define conditionals like the example below. For instance, you may check your connection at componentDidMount method and then set your props.

 render(){
          if(this.state.isConnected == 'Online' )
            return this.webView();
          else
            return this.renderAnotherView();
        }
like image 39
sekogs Avatar answered Sep 28 '22 07:09

sekogs