Bootstrap / HTML โ†’ Next.js (React JSX) Differences

๐Ÿงพ Bootstrap / HTML โ†’ Next.js (React JSX) Differences

๐Ÿ” 1๏ธโƒฃ class โ†’ className

HTML / Bootstrap

<div class="container mt-3"></div>

Next.js / React

<div className="container mt-3"></div>

๐Ÿ“Œ Reason: class JS ka reserved word hai


๐Ÿ” 2๏ธโƒฃ for โ†’ htmlFor

<label for="email">Email</label>
<label htmlFor="email">Email</label>

๐Ÿ” 3๏ธโƒฃ onclick โ†’ onClick

<button onclick="openModal()">Click</button>
<button onClick={openModal}>Click</button>

โŒ () nahi lagate (auto run ho jayega)


๐Ÿ” 4๏ธโƒฃ Inline CSS string โ†’ Object

<div style="color:red; margin-top:10px"></div>
<div style={{ color: "red", marginTop: "10px" }}></div>

๐Ÿ“Œ camelCase + double {}


๐Ÿ” 5๏ธโƒฃ style value โ†’ camelCase

background-color
backgroundColor

๐Ÿ” 6๏ธโƒฃ checked, selected โ†’ boolean

<input type="checkbox" checked>
<input type="checkbox" checked={true} />

๐Ÿ” 7๏ธโƒฃ value โ†’ state controlled

<input value="Vipul">
<input value={name} onChange={e => setName(e.target.value)} />

๐Ÿ” 8๏ธโƒฃ href โ†’ Link

<a href="/about">About</a>
import Link from "next/link";

<Link href="/about">About</Link>

๐Ÿš€ Fast navigation, no reload


๐Ÿ” 9๏ธโƒฃ img โ†’ Image (recommended)

<img src="/logo.png" />
import Image from "next/image";

<Image src="/logo.png" width={100} height={40} alt="logo" />


๐Ÿ” ๐Ÿ”Ÿ JS directly โ†’ useEffect

<script src="bootstrap.js"></script>
useEffect(() => {
import("bootstrap/dist/js/bootstrap.bundle.min.js");
}, []);

๐Ÿ” 1๏ธโƒฃ1๏ธโƒฃ document / window direct โŒ

document.getElementById("id");

โœ… Correct:

useRef()

๐Ÿ” 1๏ธโƒฃ2๏ธโƒฃ if else HTML โŒ โ†’ JSX ternary

<div>condition ? show : hide</div>
{isOpen ? <Modal /> : null}

๐Ÿ” 1๏ธโƒฃ3๏ธโƒฃ Loop (for) โ†’ map()

<li>Item</li>
{items.map(item => (
<li key={item.id}>{item.name}</li>
))}

๐Ÿ” 1๏ธโƒฃ4๏ธโƒฃ data-* attributes (same)

<button data-bs-toggle="modal"></button>
<button data-bs-toggle="modal"></button>

โœ… Bootstrap data attributes same hi rehte hain


๐Ÿ” 1๏ธโƒฃ5๏ธโƒฃ Self closing tags

<input>
<input />

๐Ÿ” 1๏ธโƒฃ6๏ธโƒฃ readonly โ†’ readOnly

<input readonly>
<input readOnly />

๐Ÿ” 1๏ธโƒฃ7๏ธโƒฃ tabindex โ†’ tabIndex

<div tabindex="0"></div>
<div tabIndex={0}></div>

๐Ÿ” 1๏ธโƒฃ8๏ธโƒฃ Comments

<!-- comment -->
{/* comment */}

๐Ÿ” 1๏ธโƒฃ9๏ธโƒฃ dangerouslySetInnerHTML

<div>HTML</div>
<div dangerouslySetInnerHTML={{ __html: html }} />

โš ๏ธ XSS risk


๐Ÿ” 2๏ธโƒฃ0๏ธโƒฃ Bootstrap icons / JS plugins

  • CSS โ†’ normal import

  • JS โ†’ useEffect only


๐Ÿง  One-look Cheatsheet (exam style)

HTML Next.js
class className
for htmlFor
onclick onClick
style=”” style={{}}
a href Link
img Image
script useEffect
document useRef

๐Ÿง  Golden line (notes me likh lo)

โ€œHTML jaisa dikhta hai, par JSX JavaScript haiโ€

Leave a Reply

Your email address will not be published. Required fields are marked *