React Flashcards

1
Q

What is React?

A

a javascript library for building user interfaces

helps you build fast and interactive UIs

it allows you to change data without reloading the page

allows you to build components and reuse them

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

What is a React element?

A

what gets returned from components

its an object that virtually describes the DOM nodes
that a component represents (or an object that describes an html element)

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

How do you mount a React element to the DOM?

A

by using ReactDOM.render() method

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

What is Babel?

A

a tool to convert ES2015+ code into a backwards compatible version of JS that can be run by older JS engines

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

What is a Plug-in?

A

a software component that adds on a specific feature to a program

when a program supports plugins, it enables customization

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

What is a Webpack loader?

A

they allow you to pre-process files as you import or “load” them

they can transform files from a different language (like TypeScript) to JavaScript
or load inline images as data URLs
or import CSS files directly from your JS modules

its recommended that you specify the them in your webpack.config.js file (by using module.rules)
or another way is inline which is specify them explicitly in each import statement

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

How can you make Babel and Webpack work together?

A

by installing babel-loader

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

What is JSX?

A

a syntax extension to JavaScript
when used in React, it describes what the UI should look like
it produces React “elements”

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

Why must the React object be imported when authoring JSX in a module?

A

because React must be in scope from your JSX code even though its not directly referenced

once we convert jsx into js, you’ll see that React.createElement is being used

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

How can you make Webpack and Babel work together to convert JSX into valid JavaScript?

A

by installing babel-loader and its plugin:

babel-loader
@babel/core
@babel/plugin-transform-react-jsx

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

What is a React component?

A

it lets you split the UI into independent, reusable pieces and think about each piece in isolation

components are like JS functions thats why we call components “Function Component”

they accept arbitrary inputs (called props) and return React elements describing what should appear on the screen

React component accepts a single “props” (stands for properties) object argument with data and returns a React element

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

How do you define a function component in React?

A
function keyword
function name (HAS TO start with a capital letter or else the function gets passed as a string)
props passed in ()
returns jsx
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you mount a component to the DOM?

A

by calling the component function in between open and closed angle brackets

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

What are props in React?

A

props is a keyword in React that is used for passing data from one component to another

props is an object

you can pass any JS expression as a prop by surrounding it with { }

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

How do you pass props to a component?

A

in a (function) component, you can pass the props object into your function by specifying it in the () of the function component

to pass props, you want to assign value to props

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

How do you write JavaScript expressions in JSX?

A

we can put any valid JS expression inside curly braces in JSX

if you pass no value for a prop, it defaults to “true”

17
Q

How do you create “class” component in React?

A
  • by using the class keyword
  • name of class for ex Welcome
    extends keyword
  • and extending to React.Component (Welcome would be a sub class of React.Component)
  • must define render() inside curly braces
18
Q

How do you access props in a class component?

A

this.props

19
Q

What is the purpose of state in React?

A

State is similar to props, but it is private and fully controlled by the component

The only place where you can assign this.state is the constructor

to modify state, use setState()

// Wrong
this.state.comment = 'Hello';
// Correct
this.setState({comment: 'Hello'});

state keeps track of something

state is for keeping tracking of values that change over time

20
Q

How to you pass an event handler to a React element?

A

by calling onClick props and passing in javascript function

21
Q

what does bind do?

A

this.handClick is binding this constructor function and assigning it to the this.handleclick of the constructor function

we want the handClick value when

22
Q

What Array method is commonly used to create a list of React elements?

A

map method

23
Q

What is the best value to use as a “key” prop when rendering lists?

A

the data’s (an array) id or unique value of the data, so react can distinct each array value

needs to be unique amongst its sibling (an array)

24
Q

What are controlled components?

A

a component that takes its current value through props and notifies changes through callbacks like onChange or onSubmit

25
Q

What two props must you pass to an input for it to be “controlled”?

A

onChange and Value

26
Q

What does fetch() return?

A

a Promise containing the response / Response object of the path in your fetch argument

27
Q

What is the default request method used by fetch()?

A

GET method

28
Q

How do you specify the request method (GET, POST, etc.) when calling fetch?

A

by declaring the request method as an object in the second argument of the Fetch method

29
Q

✧ What is the json() method?

A

takes a Response and reads it to completion

returns a promise which resolves with a JS object that is the result of parsing the body text as JSON

NOTE: despite the method being named json(), the result is not JSON but is instead the result of taking JSON as input and parsing it to produce a JAVASCRIPT OBJECT

30
Q

When does React call a component’s componentDidMount method?

A

its invoked immediately after a component is mounted (inserted into the tree)

componentDidMount runs once

a good place to initiate API calls, if you need to load data from a remote endpoint

31
Q

Name three React.Component lifecycle methods.

A

render() - only required method within a class component

constructor()

componentDidMount()

componentDidUpdate()

componentWillUnmount()

32
Q

How do you pass data to a child component?

A

by passing props

and if the props is in another component, pass this.props

33
Q

What does express.static() return?

A

returns a function that is a middleware function, a function to pass to app.use as a middleware function

34
Q

What is the local __dirname variable in a Node.js module?

A

directory name of the currently module

aka the full absolute path to that file/module

35
Q

What does the join() method of Node’s path module do?

A

joins the path specified in the method’s arguments into a string of a file path

36
Q

✧ what is express.static

A

it exposes a directory or a file to a particular URL so it’s contents can be publicly accessed

opens express file over server in default browser

(need more info)

37
Q

What is registration?

A

the process of “signing up”

38
Q

What is authentication?

A

the process of “logging in”

In digital systems, authentication is the process of accepting secrets, or “credentials”, from a client and checking them against a stored version of the credentials

39
Q

What is authorization?

A

is how digital systems decide what data or functionality is available to their users