[英]Can't use Bootstrap in React?
I'm trying to use a button in a reactJS file.我正在尝试在 reactJS 文件中使用按钮。 This is the code I have
这是我的代码
export class Add extends React.Component {
render() {
return (
<div>
<Button bsStyle="primary" bsSize="large">
Add
</Button>
</div>
);
}
}
But react is giving me:但是反应给了我:
'Button' is not defined react/jsx-no-undef
I've included bootstrap in the dependcies in package.json, as well as popper.js and jquery, and I've tried npm install bootstrap.我已经在 package.json 以及 popper.js 和 jquery 的依赖项中包含了 bootstrap,并且我已经尝试过 npm install bootstrap。 I also made sure to
我也确保
import 'bootstrap/dist/css/boostrap.min.css';
import 'bootstrap/dist/js/bootstrap.min.js';
in my mainJs file.在我的 mainJs 文件中。
I also tried using with no luck.我也尝试使用但没有运气。
AMR, AMR,
Looks like you are trying to use components so i believe you are trying to use React-Bootstrap.看起来您正在尝试使用组件,所以我相信您正在尝试使用 React-Bootstrap。 Here it goes: https://react-bootstrap.github.io/getting-started/introduction
在这里: https : //react-bootstrap.github.io/getting-started/introduction
Run following to install it first:首先运行以下命令进行安装:
npm install --save react-bootstrap
then include it in your file:然后将其包含在您的文件中:
import Button from 'react-bootstrap/lib/Button';
EDIT: Adding styles as suggested in comments:编辑:按照评论中的建议添加样式:
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
Yes you can.是的你可以。 But I recommend you check this library out.
但我建议你检查一下这个库。 ReactStrap
反应带
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.