Frequently Asked Questions About Codynn React From Zero Methodology
22 answers covering everything from basics to advanced usage.
// Basics
What exactly is a React component?
A component is a JavaScript function that returns a piece of the screen as JSX. Its name must always start with a capital letter, and it can be nested inside other components and reused anywhere. Every visual unit in a React app — a header, a card, a button group — is a component.
What is the root in a React app?
The root is the single `div` with `id='root'` in index.html. It's the container where your entire React app gets rendered. main.jsx selects that div, creates a React root, and calls `root.render()` to place your top-level App component inside it. Everything in the app ultimately lives inside this one element.
What is a JSX fragment and when do I use one?
A JSX fragment is an empty wrapper tag `<> </>` used when a component needs to return multiple sibling elements but you don't want to add an extra div to the DOM. Since a component must return a single wrapping element, fragments let you group siblings without polluting your HTML structure with meaningless wrapper divs.
What does export default do in a component file?
`export default ComponentName` at the bottom of a file makes the component available for import in other files. Without it, any import of that component fails silently — the component renders nothing and no clear error tells you why. It's the first thing to check when a component won't appear on the page.
// How To
How do I add interactivity to a React component?
Import useState at the top: `import { useState } from 'react'`. Declare state like `const [count, setCount] = useState(0)`. Use `count` in JSX via curly braces. Add handlers like `onClick={() => setCount(count + 1)}`. Every element displaying count updates automatically — no manual DOM manipulation needed, which is the whole point of React.
How do I create a new component in its own file?
Create a new file like `Header.jsx`. Write the function returning JSX, then add `export default Header` at the bottom. In App.jsx, import it with `import Header from './Header.jsx'` and place `<Header />` inside App's return JSX. Check DevTools to see the hierarchy: div#root > div (App) > header (Header).
How do I reuse one component 50 times with different content?
Create one Card component that accepts props like title and description. In App.jsx, map over a data array and render `<Card key={item.id} title={item.title} description={item.description} />` for each item. The component is written once; props supply the variation. Adding a new card means adding one object to the array — zero component changes.
How do I apply CSS in a React project?
Add CSS in index.css or a component-level .css file, then assign `className` (not class) on JSX elements to match your CSS selectors. Import the CSS file where needed. Confirm in DevTools that className compiles to class in the rendered HTML. CSS selectors target the compiled class names normally.
// Troubleshooting
Why does my page break when I remove export default App?
Without `export default App`, main.jsx cannot import App, so `root.render(<App />)` has nothing to render — the whole page breaks. export default is required for the import chain to work. This is deliberately demonstrated in the methodology by removing it so you see the breakage and understand the dependency.
Why won't my counter update when I change the value directly?
Because mutating state directly like `count = count + 1` does not trigger a re-render. React only updates the screen when you call the setter function, like `setCount(count + 1)`. The setter is the only way to change a useState value AND tell React to re-render everything using that value. Direct mutation silently does nothing visible.
Why am I getting an 'adjacent JSX elements must be wrapped' error?
You're returning multiple sibling elements without a single wrapping element. A component must return one wrapping element. Either wrap the siblings in a `<div>` or use an empty JSX fragment `<> </>`. The fragment is preferred when you don't want to add an extra div to the DOM.
Why does my JavaScript show up as literal text in the browser?
Because JavaScript only executes inside curly braces in JSX. Outside `{}` it's treated as literal text. To inject a variable, expression, or method call, wrap it in curly braces: `{variableName}`, `{2 * 4}`, `{name.toUpperCase()}`. Raw JavaScript expressions placed outside braces just print as plain characters.
Can I place components directly inside the index.html root div?
No — manually editing or placing components directly inside index.html's div#root defeats the entire purpose of React's component model. Everything should route through main.jsx, which calls root.render() with your App component. The div#root is just an empty container; React fills it. Bypassing main.jsx breaks the declarative component approach entirely.
// Comparisons
Should I use a CDN setup or Vite for my React app?
Use CDN only for quick demos — loading React, ReactDOM, and Babel via script tags lets you experiment with zero install. For any real application, use the Vite + Node.js setup. Vite compiles your JSX, bundles your packages, and live-reloads on save, which CDN cannot do properly at scale. The methodology uses CDN only to compare line counts early on.
How does JSX differ from writing plain HTML?
JSX looks like HTML but lives inside JavaScript and has stricter rules: use className not class, close every tag including self-closing ones like `<img />`, return a single wrapping element, and put JavaScript in curly braces. The payoff is injecting live JavaScript directly into markup. Vite compiles JSX into real HTML the browser understands.
How do props compare to function arguments?
Props are essentially arguments for components. You pass them as attributes on the component tag, and the component receives them as a single props object. Instead of positional arguments, you access them by name via `props.propertyName`. Like function arguments, they let one template produce different output based on the data you pass in.
What's the difference between main.jsx and App.jsx?
main.jsx is the entry point — it selects the div#root, creates a React root, and calls `root.render(<App />)`. App.jsx is the top-level component that contains Header, Flashcard, and everything else. main.jsx stays clean and only ever renders App; App orchestrates the full page and manages its child components.
// Advanced
What is the full render pipeline in a React app?
Component (JSX) → export default → import in App → App exported → imported in main.jsx → root.render() → index.html div#root → browser. Every component flows through this chain. Understanding it lets you debug any rendering issue by checking each link rather than guessing. A single broken step silently stops rendering.
What is the component hierarchy and why does it matter?
Components live inside other components. App is the top-level component containing Header, Flashcard, and everything else; main renders App; App manages its children. This nesting keeps main.jsx clean and lets App orchestrate the full page. You can visualize the hierarchy in browser DevTools: div#root > div (App) > header (Header).
What role does Babel play in the CDN demo versus Vite?
In the CDN demo, Babel is a translator that converts JSX into JavaScript the browser understands — you load it via a script tag and mark your script as `type='text/babel'`. In a Vite project, Vite handles this compilation automatically, so you never touch Babel directly. It's a behind-the-scenes translator in both cases.
Which project folders should I actually work in?
99.9% of your work happens in `src`. Key files: src/main.jsx (entry point), src/App.jsx (top-level component), index.html (contains div#root). Never touch node_modules — all library code lives there. public holds static assets like images. Ignore .gitignore, package-lock.json, and vite.config.js when starting out, and use package.json scripts to run the app.
When is it a signal that I should switch from manual DOM updates to useState?
The moment you find yourself writing multiple textContent updates when one value changes, that's the signal. Manually selecting and updating several elements whenever a value changes is exactly the Manual-Update Problem React was built to eliminate. Replace those manual updates with a single useState value referenced in JSX via curly braces.