How React Works Flashcards
In React we create apps using what king of JS syntax?
JSX
The most atomic units of React are …..
React Elements
HTML elements relate to one another in ……
in a hierachy that resembles a family tree
<section id="baked-salmon"> <h1>Baked Salmon</h1> <ul class="ingredients"> <li>2 lb salmon</li> <li>5 sprigs fresh rosemary</li> <li>2 tablespoons olive oil</li> <li>2 small lemons</li> <li>1 teaspoon kosher salt</li> <li>4 cloves of chopped garlic</li> </ul> <section class="instructions"> <h2>Cooking Instructions</h2> <p>Preheat the oven to 375 degrees.</p> <p>Lightly coat aluminum foil with oil.</p> <p>Place salmon on foil</p> <p>Cover with rosemary, sliced lemons, chopped garlic.</p> <p>Bake for 15-20 minutes until cooked through.</p> <p>Remove from oven.</p> </section> </section>
How many root elements are there and how many children are there?
One root element (in this case, a section) - which has three children: a heading, an unordered list of ingredients, and a section for the instructions.
In web development SPA stands for ?
Single-Page Applications
What features of JS lead to ease of developing SPA ?
AJAX
Asynchronous JS and XML
The DOM API is a collection of ….
Objects
DOM is made up of DOM elements; and the React DOM is made up of ……
React Elements
A React element is a description of ….
What the actual DOM element should look like.
In other words, React elements are the instructions for how the browser.
What would creating the following HTML look like in React?
```<h1 id="recipe-0">Baked
Salmon</h1>
~~~
React.createElement("h1", { id: "recipe-0" }, "Baked Salmon");
What are the arguments in the following reactJS expression?
```React.createElement(“h1”, { id: “recipe-0” }, “Baked Salmon”);
~~~
- The first argument defines the type of element we want to create. eg. h1 element.
- The second argument represents the element’s properties in this case id of recipe-0.
- The third argument represents the element’s children: any nodes that are inserted between the opening and closing tag
How would the JS literal for the following DOM element look like?
```<h1 id="recipe-0">Baked Salmon</h1>
~~~
{ \$\$typeof: Symbol(React.element), "type": "h1", "key": null, "ref": null, "props": {id: "recipe-0", children: "Baked Salmon"}, "_owner": null, "_store": {} }
- These are fields used by React to construct the DOM element.
How are react elements created and rendered?
- To created element - use the React.createElement( )
- To render use ReactDOM.render()
~~~
const dish = React.createElement(“h1”, null, “Baked Salmon”);
ReactDOM.render(dish, document.getElementById(“root”));
~~~
What are the arguments for the ReactDOM.render( ) ?
- The first argument is the DOM element to be rendered?
- The second element is the “root” or node where the element is inserted.
~~~
const dish = React.createElement(“h1”, null, “Baked Salmon”);
ReactDOM.render(dish, document.getElementById(“root”));
~~~
What would be the JS literal for the following DOM element?
```<ul>
<li>2 lb salmon</li
<li>5 sprigs fresh rosemary</li>
<li>2 tablespoons olive oil</li>
<li>2 small lemons</li><li>1 teaspoon kosher salt</li><li>4 cloves of chopped garlic</li>
</ul>
~~~
</li>
{ "type": "ul", "props": { "children": [ { "type": "li", "props": { "children": "2 lb salmon" } … }, { "type": "li", "props": { "children": "5 sprigs fresh rosemary"} … }, { "type": "li", "props": { "children": "2 tablespoons olive oil" } … }, { "type": "li", "props": { "children": "2 small lemons"} … }, { "type": "li", "props": { "children": "1 teaspoon kosher salt"} … }, { "type": "li", "props": { "children": "4 cloves of chopped garlic"} … } ] ... } }