What are the rules of JSX?
Assesses fundamental understanding of React conventions, runtime behavior, and memory/performance considerations.
Hiring managers look for precision, avoidance of ambiguous jargon, and ability to explain trade-offs under real production conditions.
The below 3 rules needs to be followed while using JSX in a react application.
- Return a single root element:
If you are returning multiple elements from a component, wrap them in a single parent element. Otherwise you will receive the below error in your browser console.
html Adjacent JSX elements must be wrapped in an enclosing tag.
- All the tags needs to be closed:
Unlike HTML, all tags needs to closed explicitly with in JSX. This rule applies for self-closing tags(like hr, br and img tags) as well.
- Use camelCase naming:
It is suggested to use camelCase naming for attributes in JSX. For example, the common attributes of HTML elements such as class, tabindex will be used as className and tabIndex.
Note: There is an exception for aria-* and data-* attributes which should be lower cased all the time.
Candidate Response Strategy & Interview Tips
- Start with a concise one-sentence summary: Deliver a direct, confident answer first before expanding into nuances.
- Demonstrate real-world trade-offs: Discuss where this approach excels and when you would avoid it in production systems.
- Discuss complexity & edge cases: Proactively explain time/space complexity or boundary conditions (null values, scale limits).
- Prepare for interviewer follow-ups: Technical hiring panels frequently probe deeper into concurrency, backward compatibility, or alternative libraries.