top of page

Javascript vs REACT

  • May 12
  • 2 min read

In my web development I have been working directly with Javascript and HTML -- I'm a fan of working with the raw language. So when ChatGPT gave me some React template, I had to ask it why? Why switch over and learn something new? Here is what it answered:


Working directly with HTML and JavaScript is fine for simpler pages, but React offers a lot of advantages, especially for larger and interactive applications like the Interactive Toolkit we're building. Here’s how React improves the workflow:


🚀 1️⃣ Component-Based Architecture

  • React breaks your UI into reusable components.

  • Each piece (like the Self-Assessment Quiz) is its own module, easy to maintain, and can be reused across your application.

  • If you need a button, form, or card in different parts of your app, you just reuse the component.

Example:

If you build a button once, you can use it everywhere:

<Button label="Submit" />

🚀 2️⃣ Virtual DOM = Better Performance

  • React uses a Virtual DOM to manage updates.

  • It only re-renders components that change, not the entire page.

  • This makes it fast and efficient, especially with frequent user interactions.


🚀 3️⃣ One-Way Data Binding = Predictability

  • Data flows in one direction, making it easier to debug.

  • If something changes, you know exactly where it came from.

  • In plain JavaScript, data can be changed from anywhere, making it harder to track.


🚀 4️⃣ React Hooks = Cleaner Logic

  • With Hooks (useState, useEffect), you can manage state and lifecycle events without complex classes.

  • It simplifies managing component state and side effects.

    Example:

    Updating the user's quiz answers:

const [answers, setAnswers] = useState({}); 

const handleChange = (id, value) => { 
	setAnswers({ ...answers, [id]: value }); 
};

CopyEdit


🚀 5️⃣ Ecosystem & Libraries

  • React has a huge ecosystem:

    • shadcn/ui for UI components

    • TailwindCSS for styling

    • Redux for state management

    • React Router for navigation

  • You can easily integrate charts, maps, and even 3D models.


🚀 6️⃣ Easier State Management

  • In plain JS, tracking what state each element is in can get messy.

  • React centralizes state handling, so it's easy to see what your app is doing at any point.


🚀 7️⃣ Server-Side Rendering & SEO-Friendly

  • Tools like Next.js allow you to pre-render your app for better SEO and faster load times.


When is HTML/JS better?

  • For very simple, static pages with no interactivity, plain HTML/JS is faster to set up.

  • If your page is just a few buttons and some text, React may be overkill.

Recent Posts

See All

Comments


© 2020 by Silvia Mazzoni, Silvia's Brainery, Santa Monica, CA

bottom of page