Introducing JSX Flashcards
What is JSX?
A syntax extension to JavaScript to be used with React to describe what the UI should look like. Example:
JSX helps create loosely coupled units called ______?
Components
What can you put inside the curly braces in JSX?
You can put any valid JavaScript expression inside the curly braces in JSX.
When JSX is split over multiple lines should it be wrapped in parenthesis?
Yes, to avoid the pitfalls of automatic semicolon insertion. https://stackoverflow.com/questions/2846283/what-are-the-rules-for-javascripts-automatic-semicolon-insertion-asi
True or False - After compilation, JSX expressions become regular JavaScript function calls and evaluate to JavaScript objects.
True! This means that you can use JSX inside of if statements and for loops, assign it to variables, accept it as arguments, and return it from functions.
Should you use quotes or curly braces for string values in JSX?
You should use quotes for string values and curly braces for expressions.
Is the following safe?
Yes! By default, React DOM escapes any values embedded in JSX before rendering them. Everything is converted to a string before being rendered. This helps prevent XSS (cross-site-scripting) attacks.
What does Babel compile JSX down to?
React.createElement() calls. These are identical:
React.creatElement()
creates “React elements” that are in the end just like everything else in JavaScript, an ______?
Object! React reads these objects and uses them to construct the DOM and keep it up to date.
What property naming convention is used in JSX instead of HTML attribute names?
Since JSX is closer to JavaScript than to HTML, React DOM uses camelCase
. For example, class becomes className
in JSX, and tabindex becomes tabIndex
.