Josie Bartilson
Posted Questions
No Question(s) posted yet!
Posted Answers
Answer
In English, “you're welcome” means "you don't owe me anything for what I did" and is the polite way to reply when someone thanks you. Another way to phrase it is "no problem." The correct way to spell it is “you're welcome” or “you are welcome” without the contraction.
Answer is posted for the following question.
Answer
Shiba Inu Price in India Today ; Coinbase ₹ 0002354, 153%, ₹ 16B ; CoinMarketCap ₹ 0002362, 166%, ₹ 1174B
Answer is posted for the following question.
What's the price of shiba coin today?
Answer
Pros · Branches available worldwide · Competitive rates for share certificates · No monthly fees on basic savings and several checking accounts
Answer is posted for the following question.
Why is navy federal a good bank?
Answer
They perform special poojas and havans to welcome Goddess Durga to take shelter in their homes Devotees also observe fasts as a mark of showing their devotion for the goddess While some observe the fasts for all nine days, some keep them in jodas (couple) - first two or the last two
Answer is posted for the following question.
Why do we keep navratri fast?
Answer
With cryptocurrencies trudging through a dark stretch, Bitcoin price today continued the declining trend by trading below $39,000 level
Answer is posted for the following question.
Why crypto prices are falling?
Answer
If you are a React JS developer, then you have already encountered keywords at the top of the React component like import and export, or export default. In this article, we are going to take a close look at these keywords.
However, this is one of the most important topics in JavaScript, known as a module. But the main purpose of this article is to understand exporting and importing components in React JS. In addition, near the end of the article, you will find a table detailing the various methods for importing and exporting components in React JS.
After completing this article you will learn:
So, without further ado, let’s get into the article!
First and foremost, what is the actual meaning of import and export in general?
Therefore, America is exporting Tesla cars, and India is importing them.
Similarly, in React JS, we need to export components, functions, or values in order to use those components in another file (module). To use those exported components in another file, we have to import them first.
So, there are two primary ways to export and import components( or values) in React JS.
We can use one or both of them in order to export and import components.
Suppose we want to export these two functions in another React component (file or module). To export these functions into another component as a named export, we just need to use the export keywords in front of the functions.
The export keyword has made these functions available to other components, allowing them to be used by other React components in the future.
//America.js
// Named import
export function Apple() {
return
I’m sending MacBook.
;}
// Named import
export function Windows() {
return
I’m sending Windows.
;}
In the above code, the ‘America.js’ component has two functions that are Apple() and Windows() and in front of these functions, the export keywords are mentioned. That means they will be used later in other React components.
We can have multiple Named exports in a React component, so we can use the curly braces { } to export more than one Named export instead of exporting individually.
See in the below code, I have grouped together all functions and variables inside the curly braces that can be easily accessible in other React components.
//America.js
function Apple() {
return
I’m sending MacBook.
;}
function Windows() {
return
I’m sending Windows.
;}
// Exporting all items at one go using curly braces.
// Named import
export { Apple, Windows };
Named import
Once we define a component with the export keyword, we can now access and import those exported functions using the import keyword.
Now we are going to import those functions and variables, which are being exported by the “America.js” component, into a component called “India.js.”
//India.js
// Named import
import { Apple } from “./America.js”;
// Named import
import { Windows } from “./America.js”;
In the above code, the import keywords are used to import the Apple() and Windows() functions, which are exported by the “America.js” file.
Also, we must enclose the functions or values in curly braces {…} and give them the same name as defined from where they are exported. That’s why these imports are called exports. We cannot change the name of the imported bindings (bindings are nothing but functions, values, or classes).
But also we can import multiple bindings into a single line of code, separated by commas ( , ).
//India.js
// Named import
import { Apple, Windows} from “./America.js”;
Now we can use these bindings inside the ‘India.js’ component.
//India.js
// Named import
import { Apple, Windows } from “./America”;
function India() {
return (
<>
>
);
}
Have a look at the illustration about Named export and import.
The default export is also used for exporting components, values, classes, etc. in React JS, but only one element can be exported to another component at a time as a default export. In other words, a file can have only one default export.
Suppose we want to export the “Tesla” component to other components from the “America.js” file as a default export, so the syntax will be like this:
//America.js
function Tesla() {
return
I’m sending the Tesla car.
;}
// Default export
export default Tesla;
In the above code, there is a function called “Tesla”, and this function is exported as a default export. We just need to put export and default keywords in front of the function.
But we can also omit the name of the function in the above code snippet because the “America.js” file represents the name of the function. Have a look at the syntax below.
//America.js
// Default export
export default function () {
return
I’m sending the Tesla car.
;}
Now we can easily import the above component into other components by following the same technique as the Named import, but there are two main differences.
//India.js
// Default import
import Car from “./America.js”;
// Named imports
import { Apple, Windows} from “./America.js”;
function India() {
return (
<>
>
);
}
In the above code, we can put any name in the place of “Car” as the default import. Have a look at the illustration below.
As you can see in the above code snippets, I’m importing named and default exported bindings in the two lines of code. But we can also import both ways on the same line of code in a component.
In order to import default and named bindings, we must keep these two main points in mind.
// India.js
// Combined named and default imports
import Car, { Apple, Windows } from “./America”;
function India() {
return (
<>
>
);
}
In the above code, the ‘Car’ is a default import but ‘Apple’ and ‘Windows’ are the Named imports.
We can also change the name of the bindings before exporting them to other components using the “as” keyword.
//America.js
function Windows() {
return
I’m sending Windows.
;}
// Named export
export { Windows as Microsoft };
In the above code snippet, I have changed the name of the Windows() function to the Microsoft() function using the “as” keyword. And this new alias name will be used when importing it into other components.
Have a look at the code below.
//India.js
// Named import
import { Microsoft } from “./America”;
function India() {
return (
<>
>
);
}
Answer is posted for the following question.
How to react export (Javascript Scripting Language)