0403 (express static, api reg etc., react routing etc.) Flashcards

1
Q

What is the purpose of the Express Static middleware?

A

it serves static files

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

What does express.static() return?

A

it returns a middlewear

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

What are several examples of static files?

A

images, index.html, main.js, styles.css? files u just get and deliver as is.

extra:
non static files: sound files, files u need server for, files you import (you are running it)

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

What is a good way to serve application images using Express?

A

put them in an images folder inside (public)?

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

What does fetch() return?

A

A Promise that resolves to a Response object.

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

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

A

GET

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

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

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

How does fetch report errors?

A

fetch is a promise so it can do that

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

How can useEffect be used to load data for a component?

A

with fetch?

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

What browser function can be used to make HTTP requests to a server in React?

A

fetch

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

How do you use useEffect to load component data just once when the component mounts?

A

by using empty brackets (an empty array) as a dependency?, e.g. [ ]

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

How do you use useEffect to load component data every time the data key changes?

A

pass that key as a dependency in the array, [ ]

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

In a large-scale production app, what are some better alternatives for loading and managing backend data?

A

Some good open source packages are React Query and Vercel SWR work.

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

errors:
500s are?
400s are?

which is client/server?

A

500 server
400 client

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

What is the purpose of React “context”?

A

To be able to pass data from a (distant) parent to many children instead of manually passing props indiviaually
.

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

What values can be stored in context?

A

static values and also values which can be updated

17
Q

How do you create context and make it available to the components?

A

import “crateContext”:

import { createContext } from ‘react’;

create it in a file and export it:

export const LevelContext = createContext(1);

18
Q

How do you access the context values?

A

by wrapping children which are going to use it and passing to them thru a parent (close or distant)

19
Q

When would you use context? (in addition to the best answer: “rarely”)

A

when u don’t want to set data manually on many children

20
Q

react-custom-hooks

21
Q

react-custom-hooks

22
Q

What is a React custom hook?

23
Q

When are custom hooks useful? When are they not required?

A

writing less with ordinary hooks.

when another hook is NOT called.

24
Q

What is the syntax (or naming convention) for writing a custom hook?

25
How do you call a custom hook?
26
When do custom hooks execute?
27
What are unit tests?
A way to check if code (usually a function) meets certain conditions and does what is intended. It's like console logging in that you can check your work, but much more sophisticated. Officiallty: A unit test is a way of testing a unit - the smallest piece of code that can be logically isolated in a system. In most programming languages, that is a function, a subroutine, a method or property. source: https://smartbear.com/learn/automated-testing/what-is-unit-testing/
28
Why is it important to write unit tests?
To test code, to refactor code, debug
29
What code should be tested with a unit test? What code is not well suited for unit tests?
a unit. small piece of code.
30
What is Jest? What are some other popular JavaScript unit testing frameworks?
A unit testing framework for JS. Others are Jest, Mocha, Jasmine, AVA
31
In JavaScript, when is scope determined?
32
What allows JavaScript functions to "remember" values from their surroundings?
33
What values does a closure contain?
all that are in scope
34
When is a closure created?
when a function is created
35
How can you tell if a function will be created as a closure?
36
In React, what is one important case where you need to know if a closure was created?
if u have a function that is a dependency in ur useEffect, u need to know if it's a closure. you will get a lint error if it's a closure. to fix this, wrap the function and use a callback.
37
what is a closure
a function which has a reference to a function and varialbes outside of it that it uses in the function