Vite builds frontend tools for developers and it leverages the latest technologies under the hood to provide a great developer experience. Fortunately, it also caters to the React ecosystem. We will use Vite’s CLI to quickly create a template React project. It requires minimal configuration and provides extremely useful tools right out of the box, allowing us to get straight to the learning.
ReactJS functional components are JavaScript functions that return a JSX element, which is a template used to define the component’s structure. JSX looks similar to HTML, but it has a special syntax that lets it be converted into JavaScript code
function Greeting() { return <h1>"I swear by my pretty floral bonnet, I will end you."</h1>;}export default Greeting;
Note: the function name must be capitlized, so React can distinguish the JSX as a React component rather than an HTML tag
JSX is a syntax extension for JavaScript that lets you write HTML-like markup inside a JavaScript file. Rather than separate rendering logic (.js) and markup (.html) in separate files, JSX allows React to separate concerns by functionality. Each component handles a specific concern (like rendering a button or form), and both the logic and its markup live together in the same file.
Multiple elements can be wrapped in a parent tag, such as a <div> or a React fragment, like <>Children</>
Unlike in HTML, in JSX, all tags must be properly closed and nested
JSX enforces these rules for clarity and consistency since it’s parsed by JavaScript, not a browser.
HTML attributes must be written in camelCase
When JSX is compiled, element attributes (like class, stroke-width, etc.) must be mapped to valid keys of JavaScript objects (i.e. can’t have dashes or reserved words like class)