Answers for "how to get current location in react"

3

react get current route

/*In the 5.1 release of react-router there is a hook called useLocation,
which returns the current location object. 
This might be useful any time you need to know the current URL.*/
import { useLocation } from 'react-router-dom';

const location = useLocation();
console.log(location.pathname);
Posted by: Guest on December-24-2020
0

get current url react router

import {withRouter} from 'react-router-dom';

const SomeComponent = withRouter(props => <MyComponent {...props}/>);

class MyComponent extends React.Component {
  SomeMethod () {
    const {pathname} = this.props.location;
  }
}
Posted by: Guest on May-21-2020
0

get location from brwoser react

npm install react-geolocated --save
Posted by: Guest on April-23-2020
0

get location from brwoser react

import React from "react";import { geolocated } from "react-geolocated"; class Demo extends React.Component {    render() {        return !this.props.isGeolocationAvailable ? (            <div>Your browser does not support Geolocation</div>        ) : !this.props.isGeolocationEnabled ? (            <div>Geolocation is not enabled</div>        ) : this.props.coords ? (            <table>                <tbody>                    <tr>                        <td>latitude</td>                        <td>{this.props.coords.latitude}</td>                    </tr>                    <tr>                        <td>longitude</td>                        <td>{this.props.coords.longitude}</td>                    </tr>                    <tr>                        <td>altitude</td>                        <td>{this.props.coords.altitude}</td>                    </tr>                    <tr>                        <td>heading</td>                        <td>{this.props.coords.heading}</td>                    </tr>                    <tr>                        <td>speed</td>                        <td>{this.props.coords.speed}</td>                    </tr>                </tbody>            </table>        ) : (            <div>Getting the location data… </div>        );    }} export default geolocated({    positionOptions: {        enableHighAccuracy: false,    },    userDecisionTimeout: 5000,})(Demo);
Posted by: Guest on April-23-2020

Code answers related to "how to get current location in react"

Code answers related to "Javascript"

Browse Popular Code Answers by Language