0403 (express static, api reg etc., react routing etc.) Flashcards
What is the purpose of the Express Static middleware?
it serves static files
What does express.static() return?
it returns a middlewear
What are several examples of static files?
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)
What is a good way to serve application images using Express?
put them in an images folder inside (public)?
What does fetch() return?
A Promise that resolves to a Response object.
What is the default request method used by fetch()?
GET
How do you specify the request method (GET, POST, etc.) when calling fetch?
How does fetch report errors?
fetch is a promise so it can do that
How can useEffect be used to load data for a component?
with fetch?
What browser function can be used to make HTTP requests to a server in React?
fetch
How do you use useEffect to load component data just once when the component mounts?
by using empty brackets (an empty array) as a dependency?, e.g. [ ]
How do you use useEffect to load component data every time the data key changes?
pass that key as a dependency in the array, [ ]
In a large-scale production app, what are some better alternatives for loading and managing backend data?
Some good open source packages are React Query and Vercel SWR work.
errors:
500s are?
400s are?
which is client/server?
500 server
400 client
What is the purpose of React “context”?
To be able to pass data from a (distant) parent to many children instead of manually passing props indiviaually
.
What values can be stored in context?
static values and also values which can be updated
How do you create context and make it available to the components?
import “crateContext”:
import { createContext } from ‘react’;
create it in a file and export it:
export const LevelContext = createContext(1);
How do you access the context values?
by wrapping children which are going to use it and passing to them thru a parent (close or distant)
When would you use context? (in addition to the best answer: “rarely”)
when u don’t want to set data manually on many children
react-custom-hooks
react-custom-hooks
What is a React custom hook?
When are custom hooks useful? When are they not required?
writing less with ordinary hooks.
when another hook is NOT called.
What is the syntax (or naming convention) for writing a custom hook?