将Bootstrap 4与React一起使用 [英] Use Bootstrap 4 with React

查看:78
本文介绍了将Bootstrap 4与React一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,我缺乏知识,但是我是新手,目前正在学习React.我只是想问一下是否要在我的React应用程序中使用Bootstrap 4,是否必须安装jQuery?我在某处读到,将jQuery与React一起使用是不行的.所以现在我想知道.谢谢回复.非常感谢您的建议.

Sorry for my lack of knowledge but I'm new and currently learning React. I just wanted to ask if I wanted to use Bootstrap 4 with my React app, do I have to install jQuery? I read somewhere that using jQuery with React is a NO-NO. So now I'm wondering. Thanks for the reply. Your advice and suggestions are truly appreciated.

推荐答案

某些功能,例如下拉菜单,模式要求JS来操作DOM,而引导程序则使用jQuery来处理DOM操作.

Certain functionalities such as dropdown, modal requires JS to manipulate the DOM, and bootstrap uses jQuery to handle the DOM manipulations.

但是,React使用虚拟DOM ,因此可以在外部操纵浏览器DOM通过jQuery的React应用程序意味着React可能不再处理状态,事件和UI呈现.而且,React广泛地期望/假设其他任何事情都不会修改DOM.

However, React uses virtual DOM, so manipulating the browser DOM outside your React app through jQuery means React is potentially no longer handling state, events and UI rendering. And React broadly expects/assumes that nothing else will be modifying the DOM.

这就是为什么 react-bootstrap

This is why react-bootstrap or reactstrap are recommended. The CSS remains exactly the same, but the components that initially require jQuery are rewritten.

此bootstrap 4 modal 为例,您需要定义 modal状态,该状态确定模态是显示还是隐藏.

Take this bootstrap 4 modal as example, you need to define modal state which determines whether the modal is being shown or hidden.

因此从本质上讲,这些React Bootstrap库将每个Bootstrap组件重写为React组件,因为CSS完全相同.

So essentially these react bootstrap libraries rewrite each bootstrap component into a React component, CSS wise it's entirely the same.

这篇关于将Bootstrap 4与React一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆