What are the rules of JSX?

React JSX, components and props · Freshers

Model answer

A component must return one parent element or a fragment (<>...</>). Every tag must be closed, including <img /> and <input />. Attributes use camelCase, such as onClick and className. You cannot use statements like if or for inside JSX, but you can use expressions: ternaries, &&, and map.

Curly braces switch from markup to JavaScript.

Learn this topic

React Components and Props Explained with Examples in the course React.js Full Course: Beginner to Advanced.

Sign in to add your own answer.

More questions