JSX Flashcards

1
Q

What is JSX?

A
  • JS is a special dialect of JS (not like HTML)
  • Browsers don’t understand JSX code, we write JSX then run tools like babel that turn it into normal JS
  • It is very similar in form and function to normal HTML
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the differences between JSX and HTML?

A
  • Adding custom styling to an element uses different syntax
  • Adding a class to an element uses different syntax
  • JSX can reference JS variables
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How can you add custom styling to an element in JSX?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Why cannot you use class property on JSX elements?

A

We should use className keyword instead of class, in order to avoid collision between JS class keyword and property that is put on JSX object that we return in React Components.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How can you embed variables in jsx?

A

We can reference a javascript function or variable by putting it in a set of curly braces like below.

    {buttonText}

Note: It is not a JavaScript object, it is the syntax that JSX uses to refer to JavaScript variables

Objects are not valid React child and will produce an error.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the JSX rules?

A
  • return only single element
  • div / section / article or Fragment
  • use camelCase for html attribute
  • className instead of class
  • close every element
  • formatting with ()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly