Can you import multiple objects from a library at once?


In the context of this exercise, can you import multiple objects from a library at once?


Yes, you can do this using “unpacking” when importing from a library.

For example, say that you wanted to import multiple functions from some library, you could do so as follows,

import { functionA, functionB, functionC } from 'library';

Another, more concrete, example is importing objects from the ‘react-router’ library.

import { Router, Switch } from 'react-router';

As in the exercise we are not mentioning which functions to import, doesn’t that import all the functions from react library?


Do we have to maintain a strict name of ‘React’ for the variable or can we use any name?


See the following:

If you’re using the JS import method then you have to use the name ‘React’. If you want to use an alias then you have to write something like:

import { functionA as funcA } from ‘library’;

1 Like

Actually, we are mentioning which part of the library to import when we write:

import React from 'react';

This code imports the React object of the react library. But, wait! There’s no curly braces in it. Then, it’s actually about the type of the export.

It can be read further from:

1 Like