Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React Fundamentals #10

Open
coryhouse opened this issue Apr 18, 2018 · 0 comments
Open

React Fundamentals #10

coryhouse opened this issue Apr 18, 2018 · 0 comments

Comments

@coryhouse
Copy link
Owner

coryhouse commented Apr 18, 2018

React Fundamentals

JSX

State

  • It's async. setState calls are batched. Why? No matter how many setState() calls in how many components you do inside a React event handler, they will produce only a single re-render at the end of the event. This is crucial for good performance in large applications because if Child and Parent each call setState() when handling a click event, you don't want to re-render the Child twice.
  • An example of state being async. Note that alert shows value that was "closed over" when the button was clicked, not the current value in state.
  • To avoid needless re-renders, avoid calling setState when data hasn't changed (or use shouldComponentUpdate)
  • Approaches for handling state in an immutable manner (or use Immer)
  • Accepts object or function. Functional setState receives prevState and props as params.
  • Accepts callback as 2nd param (but recommended to use componentDidUpdate instead)
  • Why treat state immutable?
  • Tips for using state correctly
  • Four immutable approaches
  • Where to put React state (flowchart)

Forms

Functional components

Class Components

Typechecking

Props

Keys

Hooks

useReducer tips: (below are from redux's style guide, but relevant)

useEffect Best practices

  • tkdodo Tips for simplifying useEffect
  • useEffect is taught too much / too early. It's much more important to teach ways to avoid useEffect: derived state, single source of truth for state, react keys, callback refs, useSyncExternalStore even... know about them and you likely will not need useEffect.
  • WARNING: Almost none of the effects I see in app codebases are syncing with something outside of React. It's always: if prop change, update state, if state changes, dispatch another action, or if state changes, compute something and put in another state. All of these are bad.

Component Composition

Error handling

Best practices

Quiz

  1. How does JSX differ from HTML?
  2. Is JSX required?
  3. What tool compiles JSX?
  4. What method is required on all class components?
  5. What is a lifecycle method? Can you name one?
  6. What is destructuring? Why do we do it? Contrast object destructuring with array destructuring.
  7. Why prefer const/let over var?
  8. What tool did we use to create our React app?
  9. What Hooks did we use? What were they for?
  10. Do lifecycle methods exist in function components?
  11. What tool is checking our code quality/standards and checking our code for common errors and issues?
  12. How do we declare data that changes over time?
  13. What’s the term for passing config settings into a component?
  14. How do we declare what values our component accepts?
  15. When do you declare a key? Why declare a key? What’s a good key? What’s a bad key?
  16. How do you run an npm script?
  17. Why is client-side routing preferable to server-side?
  18. How do you make a function public?
  19. How do arrow functions differ from regular functions?
  20. How do you copy an object in JS? Is it deep or shallow?
  21. When does React re-render?
  22. How do you declare state in a class? A function?
  23. What tool are we using to automatically format our code?
  24. What does JSX compile down to?
  25. What tool are we using for our mock API? How did we configure it?
  26. How did we automate starting our app and API at the same time?
  27. What array method did we use to iterate over the list of users? What does it return?
  28. What is a predicate?
  29. What is a higher order function? List some higher order functions on the array prototype.
  30. How do you copy an object in JS? Is it deep, or shallow?
  31. What is a wildcard import? When is it useful?
  32. What are the benefits and downsides of using a default export?
  33. Does const make an object immutable?
  34. Name 2 ways to declare a React component. Which should you prefer?
  35. What is the current version of JS? How often are new versions released?
  36. When is the rest operator useful?
  37. What’s the name for arguments passed to React components?
  38. How do we specify the types for each argument?
  39. How did we debug?
  40. What hook did we use to run code after render?
  41. What’s a promise? How do we handle a successful promise?
  42. How do we handle an error from a promise?
  43. When you copy an object in JS, is it deep or shallow? What’s the difference?
  44. Why is client-side routing preferable to server-side?
  45. Is the code we see in the browser what’s actually running?
@coryhouse coryhouse changed the title React Introduction React Intro Apr 20, 2018
@coryhouse coryhouse mentioned this issue Jul 24, 2018
13 tasks
@coryhouse coryhouse changed the title React Intro React Fundamentals Nov 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant