Toptal Tutorial 2/19 Flashcards
What is React?
A declarative component-based view library that helps one to build a UI.
What would be a React Framework?
By using React, Redux, and React router, we have ll the necessary to make a single page application.
Important Thing #1: React uses JSX, what is JSX?
JSX is a javascript syntax extension that somewhat resembles HTML/XML
Important Thing #2: React is based on the virtual DOM.
The virtual DOM is memory of an ideal tree that is represented by the javascript the developer writes that is later compared with the real DOM and synced with it via a process called reconciliation.
Current demand for React experts is?
React has roughly 6-10 times more job openings than Vue and 2-4 times more job openings than Angular. Why then does Vue have more stars than react on GitHub, but way fewer job openings??? No inkling why this is…..
Comparing React, Angular and Vue - who is behind their development?
React = Facebook, Angular = Google, Vue = open source.
Components can be either a function or a class. What is the difference?
Class has state and can use refs, lifecycle, and hooks whilst a function component is stateless.
What are the 2 types of class components and what is the difference between them?
Component and PureComponent. A PureComponent does a shallow comparison of props and state (reduced overhead), and Component will make full comparisons. Component can be used with shouldComponentUpdate.
Name the 7 react lifecycle methods.
Constructor(props)
componentDidMount()
componentWillUnmount()
componentDidUpdate(prevProps, prevState, snapshot)
shouldComponentUpdate(nextProps, nextState)
getSnapshotBeforeUpdate()
componentDidCatch(error, info)
Name 2 extra methods that are static.
static getDerivedStateFromError(error) statis getSnapshotBeforeUpdate(props, state)
Describe Constructor(props)
- Optional, especially with CRA being that popular, where class field declarations for JavaScript are included as default. It is pointless to declare if you are binding your methods by arrow function within the class body. A similar state can be also initialized as a class property.
- Should be used only for initializing local state for object and binding methods in ES6 classes.
Describe componentDidMount()
- Make Ajax calls here.
- If you need event listeners, subscriptions, and such, add them here.
- You can use setState here (but it will make the component rerender).
Describe componentWillUnmount()
- Cleans all stuff that is still ongoing—e.g., Ajax should be interrupted, subscription unsubscribed, timers cleared, and so on.
- Do not call setState, as it is pointless because the component will be unmounted (and you will get a warning).
Describe componentDidUpdate(prevProps, prevState, snapshot)
- Happens when the component just finished updating (doesn’t happen on initial render).
- Has three parameters that are optional to use (previous props, previous state, and a snapshot that will only appear if your component implements getSnapshotBeforeUpdate).
- Only happens if shouldComponentUpdate returns true.
- If you use setState here, you should guard it or you will land in an infinite loop.
Describe shouldComponentUpdate(nextProps, nextState)
- Only for performance optimization.
- If it returns false, then a render will NOT be invoked.
- PureComponent can be used instead if the overridden SCO is just shallow props/state comparison.