3 ms·
Here's a more canonical version of the exact same logic in react: const Root = ()=> <ConnectivityIndicatorView/> class ConnectivityIndicatorView exten
by gunn 9y ago
Here's a more canonical version of the exact same logic in react:
const Root = ()=> <ConnectivityIndicatorView/>
class ConnectivityIndicatorView extends Component {
state = { isConnected: false }
componentDidMount() {
const isConnected = Math.random() > 0.5
this.setState({ isConnected })
}
render() {
const backgroundColor = this.state.isConnected ? 'green' : 'red'
return <View style={{backgroundColor, width: 20, height: 20}}/>
}
}
And here's how I would actually write it in my own app:
const Root = ()=> <ConnectivityIndicatorView isConnected={Math.random() > 0.5}/>
const ConnectivityIndicatorView = ({isConnected})=> {
const backgroundColor = isConnected ? 'green' : 'red'
return <View style={{backgroundColor, width: 20, height: 20}}/>
}