1

how to use import statement to import functions from one component to other component.

Below is how the import statement is:

import Tool from '../Common'; import { ToolContextProvider } from '../Common'; 

This complaint of duplicate lines. So I have tried something like below,

import { ToolContextProvider, Tool} from '../Common'; 

But this doesn't seem to be correct. How can write this in one line. Could someone help me with this? Thanks.

1

2 Answers 2

4

You can import like this. Just combine both of them.

import Tool, { ToolContextProvider } from '../Common'; 
Sign up to request clarification or add additional context in comments.

Comments

4

basically there are two different type of export in javascript modules (also react included):

  1. default export
  2. named export

default export would be like :

 // someFile.js export default SomeComponent 

named export would be like

 // someFile.js export SomeOtherComponent 

importing them in other components for using them should be like:

// useCase.js import SomeComponent from './someFile' // for default export import { SomeOtherComponent } from './someFile' // for named export import SomeComponent, { SomeOtherComponent } from './someFile' // for using both 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.