React Flashcards
1
Q
What is React?
A
Front-end framework featuring deterministic view rendering, declarative UI code with JSX, and components which can be composed into larger components.
2
Q
Why is React’s determinism significant?
A
Prove that it works! If you can’t prove it, you don’t know it.
3
Q
Why are React components useful?
A
- Reusability
- Composability
- Locality - understand small units of self-contained code without understanding the context - the code around the unit you’re looking at
4
Q
Why is JSX useful?
A
- It’s an extension of JS, so you can do things like map, and native conditional expressions, logic, template literals, etc,
- Colocation - the JavaScript and the markup can be in the same file.
- Separate by concern, not by technology. Separate UI code from state logic, from side-effects, instead of separating JS, HTML, CSS.
- Abstract away DOM differences
- Abstract away from underlying tech platform - React can target ReactNative, VR, Netflix Gibbon, Canvas, WebGL, email, etc.
5
Q
Why are synthetic events useful?
A
- Smooth over cross-platform differences
- They’re automatically memory-managed (don’t need to delegate events or bind and unbind beyond the component life cycle)
- They’re object pooled (prevents janky UI due to garbage collection)
6
Q
Why are hooks useful?
A
- Write components as functions instead of classes (generally easier to read, reuse, and test)
- Organize code better
- Share reusable logic between different components
- Compose hooks to create your own custom hooks (call a hook from inside another hook)
7
Q
What are container components?
A
- Components that are connected to the data store and may have side-effects.
- Should not render their own markup — instead delegate rendering to the presentation component they wrap
- Typically, a container component in a React+Redux app would simply invoke mapStateToProps, mapDispatchToProps, and wrap the presentation component with the result
- May use composition to add in functionality
8
Q
What are presentational components?
A
- Mostly pure components, which, given the same props and context, always return the same JSX
- Don’t have side-effects
- Don’t interact directly with the store
- May use local component state for things like form inputs, as long as you can pass in an initial state so that they can be deterministically tested (hence “mostly” pure)