Both are packages built with Bootstrap-based components for React. As developers, we can use either of them. However, it is important to remember that we should keep consistent.
Table of Contents
What is Bootstrap?
Some similarities
Import Bootstrap CSS in the src/index.js
file:
import 'bootstrap/dist/css/bootstrap.css';
When using any Bootstrap components, import the required reactstrap or react-bootstrap components within src/App.js
file or your custom component files:
import {Button, Container} from "reactstrap"; function BootstrapGridTest() { return ( <Container> <h1>Fluid Grid!</h1> <p> This is a modified fluid which stretches the whole horizontal space. </p> <Button color="primary"> Submit </Button> <Button color="danger">Danger!</Button> </Container> ); } export default BootstrapGridTest;
The snippet above is aimed to test with reactstrap
package.
What is reactstrap?
It is the package of the Bootstrap components built with React.
The packages to be installed after creating a React App: npm install --save bootrap reactstrap
. We suppose that the React App has been created after the command npx create-react-app demo-bootstrap-react
completed.
GitHub: https://github.com/reactstrap/reactstrap
Documentation: https://reactstrap.github.io/?path=/story/home-installation–page
What is react-bootstrap?
It is the package of the stateless React Components for Bootstrap.
The packages to be installed after creating a React App: npm install --save bootrap react-bootstrap
. We suppose that the React App has been created after the command npx create-react-app demo-bootstrap-react
completed.
GitHub: https://github.com/react-bootstrap/react-bootstrap
Documentation: https://react-bootstrap.netlify.app/
Notes
Please take more caution when using older versions of Bootstrap. You need to install the required package exactly compatible with the version of Bootstrap. Otherwise, your application throws compiling errors.
Take away
Reactstrap makes use of class components whereas React-bootstrap makes use of functions and hooks. Both the codes produce similar output and the only difference is the use of the components. We can use either reactstrap or react-bootstrap in your React code. Remember, we cannot mess up both of them into a single project.
References
[1] Reactstrap vs. React-bootstrap, https://hackernoon.com/reactstrap-vs-react-bootstrap, accessed on Dec 31st, 2023
[2] reactstrap vs. react-bootstrap, https://dev.to/aisharajput/reactstrap-vs-react-bootstrap-18h4, accessed on Jan 1st, 2024