admin管理员组文章数量:1390767
I have to import multiple files in my App.js
. My folder structure is
/src
/ponents
layout.js
App.js
index.css
index.js
Here i want to import layout.js
file from App.js
. My code is
import React from 'react';
import Layout from './ponents/layout';
class App extends React.Component{
render(){
return (
<div>
<p>Hi</p>
</div>
);
}
}
export default App;
In my code, how to import layout.js
file ?
I have to import multiple files in my App.js
. My folder structure is
/src
/ponents
layout.js
App.js
index.css
index.js
Here i want to import layout.js
file from App.js
. My code is
import React from 'react';
import Layout from './ponents/layout';
class App extends React.Component{
render(){
return (
<div>
<p>Hi</p>
</div>
);
}
}
export default App;
In my code, how to import layout.js
file ?
-
2
import Layout from './ponents/layout';
– Anurag Awasthi Commented Jan 12, 2018 at 6:20 -
you have already imported it
import Layout from './ponents/layout';
– warl0ck Commented Jan 12, 2018 at 6:25 - but its not working – Manoj A Commented Jan 12, 2018 at 6:34
3 Answers
Reset to default 1Ideally, your layout is a ponent which you can simply import into your main. One good pratcise when creating new ponent is to create a separate folder inside ponents folder and create index.js. By doing so you can import ponents like below:
/src
/ponents
/layout
index.js
App.js
index.css
index.js
import React from 'react';
import Layout from './ponents/layout';
class App extends React.Component{
render(){
return (
<div>
<p>Hi</p>
<Layout/>
</div>
);
}
}
export default App;
It looks like you imported Layout correctly. If it is not working, perhaps you forgot to export default Layout
in layout.js?
You need to use webpack's resolve.extensions to import file paths that don't end in .js
本文标签: javascriptHow to import a File path in React JsStack Overflow
版权声明:本文标题:javascript - How to import a File path in React Js? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744754431a2623374.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论