Performance: Bootstrap with React (react-bootstrap)
Using react-bootstrap affects the bundle size and rendering speed of React apps by adding Bootstrap components as React components.
import 'bootstrap/dist/css/bootstrap.min.css'; import Button from 'react-bootstrap/Button'; function App() { return <Button variant="primary">Click me</Button>; }
import 'bootstrap/dist/css/bootstrap.min.css'; import { Button, Modal, Dropdown } from 'react-bootstrap'; function App() { return <Button variant="primary">Click me</Button>; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Import full Bootstrap CSS + all react-bootstrap components | High (many nodes from components) | Multiple reflows due to large CSS | High paint cost from styles | [X] Bad |
| Import full Bootstrap CSS + only needed react-bootstrap components | Moderate (only used components) | Single reflow after CSS load | Moderate paint cost | [!] OK |
| Use Bootstrap CSS from CDN + only needed react-bootstrap components | Low (minimal components) | Single reflow | Low paint cost | [OK] Good |
react-bootstrap in a React project?Button component from react-bootstrap?import React from 'react';
import { Button } from 'react-bootstrap';
export default function App() {
return <Button variant="success">Save</Button>;
}import React from 'react';
import { Button } from 'react-bootstrap';
function MyButton() {
return <Button variant="primary">Click Me</Button>
}
export default MyButton;Pass the test and this pattern moves unknown