I want to a notification to pop up on the screen if someone tries to view my webpage on a mobile browser, telling them that it should not be possible. I initially tried to hard code this into the App.js
class, but decided to use a component. However, when I try to see if going to mobile (via Edge's emulation available from right click + inspect element), no notification shows.
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import { render } from 'react-dom'
import { Provider as AlertProvider } from 'react-alert'
import AlertTemplate from 'react-alert-template-basic'
import { useAlert } from 'react-alert'
import { isMobile } from 'react-device-detect';
import { Alert } from 'reactstrap';
import { UncontrolledAlert } from 'reactstrap';
class Disclaimer extends Component {
constructor(props) {
super(props);
this.state = {
visible: true
};
this.onDismiss = this.onDismiss.bind(this);
}
onDismiss() {
this.setState({ visible: false });
}
render(){
return(
<Alert color="danger" isOpen={this.state.visible} toggle={this.onDismiss}>
This webpage is not optimized for mobile.
</Alert>
);
}
}
}
export default Disclaimer;
I ultimately call this component to be returned in App.js, but I can't see it. However, when I look at 'elements,' I do see it in the hierarchy, and there is a place on the screen it gives an outline, but nothing visible in terms of what the alert should do. I do have a .css file for the alert, but its just font-family
and text-align
.
UPDATE: I also have tried doing this in the App.js render()
method:
<MobileView>
<button
onLoad={() => {
if(isMobile){
alert.show('This page is not optimized for mobile!')
}
}}
>
Show Alert
</button>
</MobileView>
I changed it from button to alert, and can't see anything. That being said, when I use a browser, simulate mobile, and then inspect element, where I go to elements and styles, I can uncheck the box that has "opacity 0" or edit the value. How can I do that in the code, assuming I change button to Alert???