REACT detect mobile device react - Net-Raft.com

Welcome aboard! We are happy you are here and wish you good net-raft!




Just a Web Code Solution
join us

detect mobile device react


 432

REACT


3

// at first you install npm install react-useragent

import React from 'react';
import withUserAgent from 'react-useragent';

class App extends React.Component {
render() {
return (
<div>
{this.props.ua.mobile ? (
"mobile"
) : (
"something else"
)}
</div>
);
}
}

export default withUserAgent(App);


By        
The power of the user (%)
58%

REACT


2

import React from 'react';

class App extends React.Component {
constructor() {
super();

this.state = {
data: []
}

this.setStateHandler = this.setStateHandler.bind(this);
};

setStateHandler() {
var isMobile = window.innerWidth <= 500
if (isMobile) {
this.setState({data: "mobile"})
} else {
this.setState({data: "something else"})
}
};

render() {
return (
<div>
<button onClick = {this.setStateHandler}>Click</button>
<h2>{this.state.data}</h2>
</div>
);
}
}

export default App;


By        
The power of the user (%)
58%

REACT


0

<!DOCTYPE html>
<html>
<head>
</head>
<body>

<div id="my-div"></div>

<script src="https://fb.me/react-0.14.3.min.js "></script>
<script src="https://fb.me/react-dom-0.14.3.min.js "></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.34/browser.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/babel">

var MyReact = React.createClass({
render: function() {
return (
<p>{this.props.a}</p>
);
}
});

var a;
var b;
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
b = "mobile device";
}
else {
b = "something else";
}

ReactDOM.render(
<MyReact a={b}/>,
document.getElementById('my-div')
);

</script>

</body>
</html>


By        
The power of the user (%)
58%



The most helpful REACT solutions

How to get client ip address using react ?How to get client ip address using react ?REACT

Click to see more ...

  15.5K     421

how to get the type of a device using react ?how to get the type of a device using react ?REACT

Click to see more ...

  1.9K     214

create digital clock reactcreate digital clock reactREACT

Click to see more ...

  1.4K     141

country dropdown using reactcountry dropdown using reactREACT

Click to see more ...

  1.1K     127

create alarm clock using reactcreate alarm clock using reactREACT

Click to see more ...

  3.8K     113

How to get latitude and longitude using react/javascript ?How to get latitude and longitude using react/javascript ?REACT

Click to see more ...

  867     108

get client country reactget client country reactREACT

Click to see more ...

  607     82

get ip address reactget ip address reactREACT

Click to see more ...

  798     81

time ago reacttime ago reactREACT

Click to see more ...

  441     74

detect mobile device reactdetect mobile device reactREACT

Click to see more ...

  432     58

Welcome aboard!
We are happy you are here and
wish you good net-raft!