Search

React x Bootstrap

React Bootstrap ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

React ํ”„๋กœ์ ํŠธ์—์„œ Bootstrap ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€ 2 ๊ฐ€์ง€๊ฐ€ ์žˆ๋‹ค.
1.
bootstrap ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ (๊ทธ๋ƒฅ Bootstrap)
2.
react-bootstrap ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ (React ์šฉ Bootstrap)

bootstrap vs react-bootstrap

1.
Bootstrap
โ€ข
Bootstrap์€ ์›๋ž˜ jQuery์™€ ํ•จ๊ป˜ ์‚ฌ์šฉ๋˜๋Š” CSS ํ”„๋ ˆ์ž„์›Œํฌ๋กœ, jQuery ๊ธฐ๋ฐ˜์˜ JavaScript ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
โ€ข
React ํ”„๋กœ์ ํŠธ์—์„œ Bootstrap์„ ์‚ฌ์šฉํ•˜๋ ค๋ฉด Bootstrap CSS ํŒŒ์ผ์„ ํ”„๋กœ์ ํŠธ์— ์ถ”๊ฐ€ํ•˜๊ณ , ํ•„์š”ํ•œ ๊ฒฝ์šฐ jQuery์™€ Popper.js๋„ ์ถ”๊ฐ€ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
โ€ข
Bootstrap์˜ JavaScript ๊ธฐ๋Šฅ์€ React์™€ ์–ด์šธ๋ฆฌ์ง€ ์•Š์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํŠนํžˆ, React๋Š” ๊ฐ€์ƒ DOM์„ ์‚ฌ์šฉํ•˜๋ฉฐ, jQuery ๊ธฐ๋ฐ˜์˜ DOM ์กฐ์ž‘์€ React์˜ ์ฒ ํ•™๊ณผ ๋‹ค๋ฅผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
import logo from './logo.svg'; import './App.css'; import 'bootstrap/dist/css/bootstrap.min.css'; function App() { return ( <div className="container"> <h1>Hello, Bootstrap!</h1> <button className="btn btn-primary">Click me</button> </div> ); } export default App;
JavaScript
๋ณต์‚ฌ
2.
react-bootstrap ์‚ฌ์šฉ:
โ€ข
react-bootstrap์€ Bootstrap์˜ React ๊ตฌํ˜„์„ ์ œ๊ณตํ•˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ž…๋‹ˆ๋‹ค. ์ด๋Š” React ์ปดํฌ๋„ŒํŠธ๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ์–ด React์™€์˜ ํ†ตํ•ฉ์ด ๋”์šฑ ์šฉ์ดํ•ฉ๋‹ˆ๋‹ค.
โ€ข
react-bootstrap์„ ์‚ฌ์šฉํ•˜๋ฉด Bootstrap์˜ ๊ธฐ๋Šฅ์„ React ์Šคํƒ€์ผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, Bootstrap์˜ "Alert" ์ปดํฌ๋„ŒํŠธ๋ฅผ react-bootstrap์„ ์‚ฌ์šฉํ•˜์—ฌ React ์Šคํƒ€์ผ๋กœ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
โ€ข
react-bootstrap์€ Bootstrap์˜ ์Šคํƒ€์ผ์„ ๊ฐ€์ ธ์˜ค๊ธฐ ์œ„ํ•ด Bootstrap CSS ํŒŒ์ผ์„ ์ถ”๊ฐ€ํ•˜๋Š” ๋Œ€์‹ , Bootstrap์˜ ์Šคํƒ€์ผ์„ ์ง์ ‘ React ์ปดํฌ๋„ŒํŠธ๋กœ ๊ตฌํ˜„ํ•˜์—ฌ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
import React from 'react'; import { Container, Button } from 'react-bootstrap'; import 'bootstrap/dist/css/bootstrap.min.css'; function App() { return ( <Container> <h1>Hello, Bootstrap!</h1> <Button variant="primary">Click me</Button> </Container> ); } export default App;
JavaScript
๋ณต์‚ฌ

Bootstrap

Bootstrap์€ ์›น ๊ฐœ๋ฐœ์„ ์œ„ํ•œ ์˜คํ”ˆ ์†Œ์Šค ํ”„๋ก ํŠธ์—”๋“œ ํ”„๋ ˆ์ž„์›Œํฌ๋กœ, ํŠธ์œ„ํ„ฐ์—์„œ ๊ฐœ๋ฐœํ•˜์˜€์Šต๋‹ˆ๋‹ค. ์ฃผ๋กœ HTML, CSS, JavaScript๋ฅผ ์ด์šฉํ•˜์—ฌ ๋น ๋ฅด๊ณ  ์‰ฝ๊ฒŒ ๋ชจ๋ฐ”์ผ ์šฐ์„ ์˜ ๋ฐ˜์‘ํ˜• ์›น ํŽ˜์ด์ง€๋ฅผ ๊ตฌ์ถ•ํ•  ์ˆ˜ ์žˆ๋„๋ก ๋„์™€์ฃผ๋Š” ๋„๊ตฌ์™€ ๋””์ž์ธ ๋ชจ์Œ์ž…๋‹ˆ๋‹ค.

React ์—์„œ Bootstrap ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•

1.
React ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ
2.
Bootstrap ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ค์น˜
3.
Bootstrap import
4.
ํด๋ž˜์Šค ์†์„ฑ ๋ฐ ์ƒํƒœ๊ฐ’์„ ์ด์šฉํ•˜์—ฌ ์Šคํƒ€์ผ ์ ์šฉ

React ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ

npx create-react-app bootstrap-react-app
Shell
๋ณต์‚ฌ

Bootstrap ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ค์น˜

cd bootstrap-react-app npm install bootstrap@5
Shell
๋ณต์‚ฌ

Bootstrap import

โ€ข
src/index.css
/* src/index.css */ /* ๊ธฐ์กด ์Šคํƒ€์ผ ์œ ์ง€ */ /* Bootstrap 5 ์Šคํƒ€์ผ ์ถ”๊ฐ€ */ @import "~bootstrap/dist/css/bootstrap.min.css";
CSS
๋ณต์‚ฌ
โ€ข
src/App.js
import 'bootstrap/dist/css/bootstrap.min.css';
JavaScript
๋ณต์‚ฌ

ํด๋ž˜์Šค ์†์„ฑ ๋ฐ ์ƒํƒœ๊ฐ’์„ ์ด์šฉํ•˜์—ฌ ์Šคํƒ€์ผ ์ ์šฉ

import logo from './logo.svg'; import './App.css'; import 'bootstrap/dist/css/bootstrap.min.css'; function App() { return ( <div className="container"> <h1>Hello, Bootstrap!</h1> <button className="btn btn-primary">Click me</button> </div> ); } export default App;
HTML
๋ณต์‚ฌ

์‹คํ–‰ ๊ฒฐ๊ณผ

react-bootstrap

React ํ”„๋กœ์ ํŠธ์—์„œ Bootstrap ์Šคํƒ€์ผ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ๋„์™€์ฃผ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ
react-bootstrap์€ Bootstrap์˜ ๊ธฐ๋Šฅ์„ React ์ปดํฌ๋„ŒํŠธ๋กœ ๋ž˜ํ•‘ํ•˜์—ฌ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด React ๊ธฐ๋ฐ˜์˜ ํ”„๋กœ์ ํŠธ์—์„œ๋„ Bootstrap์˜ ๊ฐ•๋ ฅํ•œ ์Šคํƒ€์ผ ๋ฐ ๊ตฌ์„ฑ ์š”์†Œ๋ฅผ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ฃผ์š” ํŠน์ง• ๋ฐ ์žฅ์ 

1.
React ์ปดํฌ๋„ŒํŠธ๋กœ ๊ตฌํ˜„๋œ Bootstrap: Bootstrap์˜ ๋‹ค์–‘ํ•œ ๊ตฌ์„ฑ ์š”์†Œ๋ฅผ React ์ปดํฌ๋„ŒํŠธ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
2.
React ์ƒํƒœ๊ณ„์™€์˜ ํ†ตํ•ฉ: React ํ”„๋กœ์ ํŠธ์—์„œ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก React ์ƒํƒœ๊ณ„์™€ ํ†ตํ•ฉ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
3.
๋ชจ๋“ˆ์„ฑ ๋ฐ ์ปค์Šคํ„ฐ๋งˆ์ด์ง•: Bootstrap ์Šคํƒ€์ผ์„ ๋ชจ๋“ˆ๋กœ ์‚ฌ์šฉํ•˜๋ฉด์„œ ํ•„์š”ํ•œ ๊ฒฝ์šฐ ๊ฐ ๊ตฌ์„ฑ ์š”์†Œ๋ฅผ ์ปค์Šคํ„ฐ๋งˆ์ด์ง•ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
4.
์œ ์ง€๋ณด์ˆ˜ ์šฉ์ด์„ฑ: Bootstrap ์—…๋ฐ์ดํŠธ๊ฐ€ ์žˆ์„ ๋•Œ, ํ•ด๋‹น ์—…๋ฐ์ดํŠธ๋ฅผ ์‰ฝ๊ฒŒ ํ†ตํ•ฉํ•˜์—ฌ ํ”„๋กœ์ ํŠธ๋ฅผ ์ตœ์‹  ์ƒํƒœ๋กœ ์œ ์ง€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์˜ˆ๋ฅผ ๋“ค์–ด, Button, Navbar, Modal๊ณผ ๊ฐ™์€ Bootstrap์˜ ๊ตฌ์„ฑ ์š”์†Œ๋ฅผ react-bootstrap์—์„œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด React ์ปดํฌ๋„ŒํŠธ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

bootstrap vs react-bootstrap

React-Bootstrap์€ React๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Bootstrap ๊ตฌ์„ฑ ์š”์†Œ๋ฅผ ์™„์ „ํžˆ ๋‹ค์‹œ ๊ตฌํ˜„ํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค.ย ๋˜๋Š” jQuery ์— ์ข…์†๋˜์ง€ย bootstrap.jsย ์•Š์Šต๋‹ˆ๋‹คย ย ย .ย React ์„ค์ •๊ณผ React-Bootstrap์ด ์„ค์น˜๋˜์–ด ์žˆ๋‹ค๋ฉด ํ•„์š”ํ•œ ๋ชจ๋“  ๊ฒƒ์„ ๊ฐ–์ถ˜ ๊ฒƒ์ž…๋‹ˆ๋‹ค.
jQuery๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฉ”์„œ๋“œ์™€ ์ด๋ฒคํŠธ๋Š” DOM์„ ์ง์ ‘ ์กฐ์ž‘ํ•˜์—ฌ ๋ช…๋ น์ ์œผ๋กœ ์ˆ˜ํ–‰๋ฉ๋‹ˆ๋‹ค.ย ๋Œ€์กฐ์ ์œผ๋กœ React๋Š” ์ƒํƒœ ์—…๋ฐ์ดํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ€์ƒ DOM์„ ์—…๋ฐ์ดํŠธํ•ฉ๋‹ˆ๋‹ค.ย ์ด๋Ÿฐ ๋ฐฉ์‹์œผ๋กœ React-Bootstrap์€ Bootstrap ๊ธฐ๋Šฅ์„ React์˜ ๊ฐ€์ƒ DOM์— ํ†ตํ•ฉํ•˜์—ฌ ๋ณด๋‹ค ์•ˆ์ •์ ์ธ ์†”๋ฃจ์…˜์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

react-bootstrap ์‚ฌ์šฉ ๋ฐฉ๋ฒ•

1.
React ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ
2.
react-bootstrap ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ค์น˜
3.
react-bootstrap ์ปดํฌ๋„ŒํŠธ import
4.
react-bootstrap์˜ React ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉ

React ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ

npx create-react-app react-bootstrap-app
Shell
๋ณต์‚ฌ

react-bootstrap ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ค์น˜

npm install react-bootstrap bootstrap
Shell
๋ณต์‚ฌ

react-bootstrap ์ปดํฌ๋„ŒํŠธ import

import { Container, Button } from 'react-bootstrap'; import 'bootstrap/dist/css/bootstrap.min.css';
JavaScript
๋ณต์‚ฌ

react-bootstrap์˜ React ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉ

import React from 'react'; import { Container, Button } from 'react-bootstrap'; import 'bootstrap/dist/css/bootstrap.min.css'; function App() { return ( <Container> <h1>Hello, Bootstrap!</h1> <Button variant="primary">Click me</Button> </Container> ); } export default App;
JavaScript
๋ณต์‚ฌ

์‹คํ–‰ ๊ฒฐ๊ณผ

๋” ์ž์„ธํ•œ ๊ฐ€์ด๋“œ์™€ ๊ฐœ๋ฐœ ๋ฌธ์„œ๋Š” ์•„๋ž˜ ๋งํฌ์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.