Custom Hooks in React
15 questions · 12 min · Medium
Test your knowledge of JSX syntax and rendering in ReactJS, including JSX expressions, elements, fragments, conditional rendering, list rendering, attributes, event handling, component rendering, and the use of keys.
No sign-up needed · Last updated:
Score: 0 00:00
Create a free account to keep your scores and track your progress. It is optional.
15 questions · 12 min · Medium
20 questions · 15 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
A. JavaScript XML
JSX stands for JavaScript XML. It is a syntax extension that allows developers to describe UI elements using HTML-like markup within JavaScript.
C. Curly braces {}
Curly braces allow JavaScript expressions to be evaluated inside JSX, such as <p>{2 + 3}</p>.
B. <h1>{title}</h1>
Curly braces tell JSX to evaluate the JavaScript variable title and render its value rather than displaying the literal word title.
D. The elements must be wrapped in a single parent element or a Fragment
A component must return one root JSX element. Multiple sibling elements can be wrapped in a parent element or a Fragment.
A. <><h1>Title</h1><p>Text</p></>
The short Fragment syntax <>...</> groups multiple JSX elements without adding an extra DOM node.
A. className="container"
React JSX uses className to specify a CSS class on an element.
C. <p style={{ color: 'red' }}>Hello</p>
The style attribute in JSX accepts a JavaScript object. The outer braces enter JavaScript expression mode, and the inner braces define the style object.
B. Using a ternary expression inside curly braces
A ternary expression can select which element to render, such as {isLoggedIn ? <Dashboard /> : <Login />}.
D. map()
The map() method transforms each array item into a JSX element, allowing React to render a collection of elements.
A. To help React identify items between renders
Keys help React match list items across renders so it can update, insert, or remove elements efficiently and correctly.
B. {condition && <p>Message</p>}
The logical AND operator renders the paragraph when condition is truthy. Be careful when the left operand can be 0, because React may render that number.
C. onClick
React uses camelCase event props such as onClick. The value is typically a function reference, for example onClick={handleClick}.
A. The paragraph displays 8
JSX evaluates the JavaScript expression inside curly braces and renders the resulting number as text.
D. {/* This is a JSX comment */}
JSX comments are written inside JavaScript expression braces using the block comment syntax.
B. createRoot()
The createRoot() API from react-dom/client creates a React root for a DOM container. Calling root.render() then renders the React component tree into that root.