Responsive to Render Appearance

How can I visualize views conditionally? Example: if my application did not connect to the Internet - display a representation of the error, if connected - visualize a WebView? Is it possible with a response to the native? I want to do not clean html

+5
source share
3 answers

The logic for visualizing views is conditionally using your example:

render() { if (!this.state.isConnected) { // error return ( <View></View> ); } else { return ( // webview <WebView /> ); } } 
+4
source

In your rendering method, you can define conventions like the one below. For example, you can test your connection using the componentDidMount method, and then set your details.

  render(){ if(this.state.isConnected == 'Online' ) return this.webView(); else return this.renderAnotherView(); } 
+3
source

If it is specific to WebView, this component contains two rendering functions.

renderError function

A function that returns a view to show if there is an error.

renderLoading function

A function that returns a loading indicator.

WebView component documents .

With the renderError function, you can return the displayed view, there the error including the application is not connected to the Internet.

0
source

Source: https://habr.com/ru/post/1245312/


All Articles