[英]How to make and import reusable components in NEXTJS
How to make and import reusable components in NEXTJS如何在 NEXTJS 中制作和导入可重用组件
I am new to nextjs but I am familiar with react.我是 nextjs 的新手,但我熟悉 react。
Next JS confused me a bit when making reusable components. Next JS 在制作可重用组件时让我有些困惑。
For example:-例如:-
In React - we create reusable components like the code mentioned below在 React 中 - 我们创建可重用的组件,如下面提到的代码
Code Path ----> src/components/button.js代码路径----> src/components/button.js
import React from 'react';
const ButtonComponent = (props) => {
return (
<>
<button>{props.children}</button>
</>
)
}
export default ButtonComponent;
But can this same code be used in NEXTJS as well?但是同样的代码也可以在 NEXTJS 中使用吗?
If yes, then where should be the path of the components directory?如果是,那么组件目录的路径应该在哪里?
Update 1:更新1:
My next js folder structure我的下一个 js 文件夹结构
https://prnt.sc/26bqbks https://prnt.sc/26bqbks
But now the problem is if I am trying to use react bootstrap it gives me an error that但是现在的问题是,如果我尝试使用 react bootstrap 它会给我一个错误
module not found
未找到模块
Screenshot -> https://prnt.sc/26bqca7屏幕截图-> https://prnt.sc/26bqca7
Update 2:更新 2:
Ok I have re-installed react-bootstrap and now I get the error mentioned in the screenshot ---> https://prnt.sc/26bqinu好的,我已经重新安装了 react-bootstrap,现在我得到了屏幕截图中提到的错误 ---> https://prnt.sc/26bqinu
Update 3更新 3
Repo code回购代码
https://github.com/Yusufzai/test-next-js-bootstrap https://github.com/Yusufzai/test-next-js-bootstrap
Your path should be relative to your current page.您的路径应该相对于您当前的页面。
Suppose you are having a page pages/test.js
.假设您有一个页面
pages/test.js
。
test.js测试.js
import Component "../components/Component";
// use here
I downloaded your repo.我下载了你的仓库。 Was able to fire it up just fine.
能够很好地点燃它。 Just delete your node_modules folder.
只需删除您的 node_modules 文件夹。 Restart your server.
重新启动您的服务器。 Then run npm i.
然后运行 npm i。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.