title | dateModified | dateCreated | tags | parent | week | topics | content | |||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Week-09 |
2024-09-11 |
2024-08-20 |
|
[[Intro to React V3]] |
9 |
|
lesson plan |
[!drafting note] #drafting-note
- let's also include updating the todo object with a completed bool so we can work with longer lists in future lessons
- focus on url params for searching and filtering
- Limiting Network Requests
- Refetching
- useMemo and useCallback
By the end of this lesson, we will:
- explain the importance of limiting fetch requests to APIs
- use useCallback to prevent unnecessary data fetching
- explain the importance of fresh data in an application
- construct a fetch request to retrieve filtered or sorted data
[!left off here] This is about doing fresh fetches for filters and sorts as opposed to re-querying locally stored data.
- compare and contrast useCallback and useMemo
- reasons for caching
- even on fast networks, large data transfer is still slow compared to the instantaneous updates in desktop applications - minimize expensive transfers
- APIs may have rate limitations & eventually throttle requests
- using useCallback instead of useEffect allows us to prevent network calls every time the component refreshes
- function is saved across renders
- only called when item in its dependency array is updated
- unlike useEffect that also fires every time a component re-renders
- race conditions
- search query sends request every during each key press -> cannot guarantee that each request will return in order
[!drafting note] #drafting-note pagination is discussed in [[Week-12]]
- data becomes outdated
- social media feeds always adding new
- stores merchandise runs out
- news articles get updates and corrections
- not all data may be sent at once
- filters and searches don't need to send all system entries
- use query value as useCallback dependency
- useCallback
- saves function across renders
- called when dependency is updated
- useMemo
- saves the results returned from a function call
- returns result again only when dependency is updated
- optimization tool for expensive functions or components
- can wrap a component with useMemo (React.memo() HOC is preferred for this though)
- not full memoization! - only compares current state to previous state
- re-renders only if props change - does not save all previous states
After completing this week's assignment, the app should be able to:
- capability 1
- capability 2
- capability n
- step 1
- step 2
- step n
- step 1
- step 2
- step n
- step 1
- step 2
- step n