React.js Flashcards

1
Q

What is React?

A

Front-end javascript library that makes it easier to make user interfaces
Very popular in 2019

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

Benefits of React

A

Re-usability
Organization
Concise code
Scales well

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

Components

A

Contains its own html, css, js

Can update itself without affecting other components

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

Intro to Code Sandbox and Structure to the Module

A

Code Sandbox is a nice to use IDE on the browser that contains all the setup needed for coding

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

Intro to JSX and Babel

A

Every react html has a <div>

</div>

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

.render()

A

Inserts HTML into the website, through the javascript file/code
Arguments
1. What to show
Note: only takes 1 element
2. Where to show
In this case, document.getElementById(‘root’)
3. Callback

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

React creates JSX files

A

HTML code inside of a Javascript file

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

Babel

A
Javascript compiler inside of React module
Takes any Javascript code and converts it into an equivalent Javascript code that can be read by any browser
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Javascript Expressions in JSX & ES6 Template Literals

A

We can insert Javascript inside an HTML inside of a javascript
{}
Only values or expressions can be placed, not statements

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

JSX Attributes & Styling React Elements

A

In the JSX file, instead of using “class=”, we would have to use “className=”
HTML attributes for JSX must be camelCase

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

Inline Styling for React Elements

A

Even though it looks like HTML, it is not, it’s JSX

For inline styling, we need to pass in a javascript object

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

React Components (1)

A

Components can help us break down a large codebase into smaller ones, plus the benefit of reuseability
To create a React Component, create a function that has the naming convention in Pascal form
Create a new file with .jsx extension

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

React Components (2)

A

In the index.js file, import the .jsx file and use the component like how you would use an HTML element

Normally, React app’s in their index.js have an App component, which comprises of all of the UI
All the components will have their own .jsx file
And all the components will be organized into sub-directories

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

Javascript ES6 - Import, Export and Modules

A

export default
There can only be 1 default export for a .jsx file
Export multiple functions, values, objects, ….
export {}
import * as from “”
wildcard import is discouraged, as it reduces readability

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

Starting up a React app // React Props

A

Is a method to pass in parameters from JSX html to the React functions
We can also pass in functions as well
name, imageURL, tel, email are like parameters that get passed to Card, with all the parameters inside of props

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

Props

A

Creates a new javascript object with parameters

17
Q

React Dev Tools

A

Displays React DOM Tree

Install extension: React Developer Tools

18
Q

Mapping Data to Components

.map()

A

“key” - unique key value for props to distinguish array values
Only used by the backend in React

19
Q

Javascript ES6 Map/Filter/Reduce

Map

A

.map()

Creates a new array by performing function on items in the original array

20
Q

Filter

A

.filter()

Creates a new array by keeping the items that evaluate to true

21
Q

Reduce

A

.reduce()

Creates an accumulated value, based on operation to each item in the original array

22
Q

Find

A

.find()

Finds and returns the first item that matches the condition

23
Q

FindIndex

A

.findIndex()

Finds and returns the first item index that matches the condition

24
Q

Javascript ES6 Arrow Functions (Fat Arrow)

A
Shorter way of writing a javascript function
Can omit the keyword function
Used for anonymous functions
1 parameter (no need for parentheses)
 => {function body}
2 or more parameters (need parantheses)
( => {function body})
If function body is only 1 line, then we can omit the {} and “return”
25
Q

React Conditional Rendering with Ternary Operations & AND

A

Ternary Operator

Ternary Operator is treated as an expression, so it can be placed inside the JSX file inside with HTML-looking code

In Javascript, we can do a similar method to ternary operator by using && because if the first condition in && is true, the second condition will be executed

If currentTime is greater than true, the <h1> will be called
</h1>

26
Q

State in React - Declarative vs Imperative Programming

Declarative

A

React uses
UI is dependent on conditions of a state variable
Given , the should be …

Benefits
Easier to reason about
Fewer things can go wrong

Cons
Needs to re-do a lot of work all the time

Expensive
Can create brand new ui elements and rerendering

Imperative
Getting hold of an item and setting its attribute to a new value

27
Q

React Hooks - useState

A

Adds dynamic interactivity
Must use a hook inside a component
Each state is local to a component

useState()
parm - Starting state value

Returns an array with 2 items

  1. State value
  2. TBA

Benefits
Will only re-render the ui element that is needed

28
Q

Javascript Object & Array Destructuring

A

Data

Destructuring complex data

29
Q

Event Handling in React

//

HTML Event Attributes

A

https://www.w3schools.com/html/html_attributes.asp

Event Attributes can add more event handling types, such as onmouseout, onclick, …

30
Q

React Forms

A

Controlled Components
https://reactjs.org/docs/forms.html#controlled-components
when submitted, will refresh to make a POST or a GET request
Will call method called onSubmit
event.preventDefault()
Prevents the default next step of the event
1. Override
2. Add preventDefault

31
Q

Class Components vs Functional Components

Hooks vs Classes

A
Class
class App extends React.Component { … render(){ … } }
Hook
function App() { … }
Can only use for Components
Makes it easier to maintain state
32
Q

Changing Complex State

A

We can have useState store an object to initialize
In the update function of useState()
We can pass in an anonymous function, which has the previous value as the parameter

33
Q

JavaScript ES6 Spread Operator

A


Can work with arrays and object inserts
Gives easy functionality to insert arrays and objects into other arrays and objects

34
Q

Managing a Component Tree

A

Can pass in function pointers in props from parent components to child components