Pretty self explanatory, can I do something like this in react/es6?
export function BaseContainer() {} as Container;
I’m programming with a editor on my phone and cant run to test. I also haven’t found anything on google regarding this so maybe this can help another on the same path
>Solution :
yes, you can do it.
Here is the basic example which may help you:
const App = () => {
return (
<h1>I'm from app</h1>
)
}
const App2 = () => {
return (
<h1>I'm from app 2</h1>
)
}
export {
App as MyApp,
App2 as MyApp2
}
In here, I’ve allias my component with MyApp Name.
OR
you can also allias while importing your component.
Here is the basic example code:
const App = () => {
return (
<h1>I'm from app</h1>
)
}
const App2 = () => {
return (
<h1>I'm from app 2</h1>
)
}
export {
App,
App2
}
and while importing you can do like this:
imoprt {App as MyApp, App2 as MyApp2} from "/path"
And for default export you do not need to worry about allias, you can export your component by any name and import it with any name. Here is the code:
// component.js
const App = () => {
return (
<h1>I'm from component</h1>
)
}
export default App;
And in main App you can import this component by any name:
// main.js
import MyComponent from "./component"
const Main = () => {
return (
<MyComponent />
)
}