What does it mean when you import something as multiple? so for example,
import {
BrowserRouter as Router,
Route,
Link
} from 'react-router-dom'
This is just an example from react router and the javascript documentation only shows example of one declaration after 'as'
It looks like it's importing BrowserRouter as Router, Route and Link so all three variables referred to the same library. If I am right, why would you ever want to do that?
So is it the same as var Router, Route, Link = require('react-router-dom').BrowserRouter();
?
The statement
import {
BrowserRouter as Router,
Route,
Link
} from 'react-router-dom'
selectively imports BrowserRouter
, Route
and Link
from react-router-dom
. The as Router
statement makes BrowserRouter
available under the name Router
(instead of BrowserRouter
). The names of Route
and Link
are not changed.
It is equivalent to:
const Router = require("react-router-dom").BrowserRouter;
const Route = require("react-router-dom").Route;
const Link = require("react-router-dom").Link;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With