W7. ReactJS Flashcards
What issues are there with AJAX?
DOM Manipulation Problems
- can be slow due to reflow
- can be complex
- need to know a lot about current state to update it to new one
- developer’s responsibility to keep data and DOM synchronized
Monolithic code
- no enforced separation of concerns between different parts of the page
- state ends up mixed in and not encapsulated properly
- code hard to read, write and maintain
What is a Model-View-Controller (MVC)
MVC breaks system up into three parts:
MODEL - responsible for reading and writing data
VIEW - responsible for displaying user interface and notifying system when user interacts
CONTROLLER - responsible for the logic that acts on events from view and updates model and view appropriately
What is reactive programming?
Where the output of a computation is updated automatically when the inputs change
- expression sets up a relationship so if variables are changed it will automatically recalculate and update all values (like excel spreadsheet)
What is functional programming?
One of the four main programming paradigms.
In this context will focus on:
- Pure Functions: return value same for every element, inputs and outputs completely capture behaviour of function
- Higher-Order Functions: can have functions as arguments or return functions (e.g. map, filter & reduce)
What is functional reactive programming?
Create chains of higher order functions where updates are made automatically along chain when input values change (pipelines of data transformations).
What are Pure Views in ReactJS?
- view part of MVC (takes in model and returns a bunch of user interface descriptions)
- pure-function for each component
- inputs to each function are relevant part of the model, can transform them using chains of higher order functions
- components composed hierarchically
What is ReactJS?
- JS library for building user interfaces
- lets you write interfaces as a set of declarative components
- view part of MVC
- pure function maps model to view
What is JSX?
Extension of Javascript with XML-like literals
- makes react more like HTML when rendering DOM elements
What is the virtual DOM?
lightweight data structure describing current state of the component as a tree of DOM elements
- means programmer doesn’t need to explicitly describe mutations to the DOM - just need to specify how it should look
(“Render” method call returns a fragment of the virtual DOM)
What are the two ways to define new types of component in ReactJS?
- functions: take in an object containing component’s properties and returns a Virtual DOM fragment
- classes: inherit from React.component and have render methods that return the sub-component tree (JSX), props passed into constructor
(class components can also have their own local state)
What are stateful components?
React class components can have their own state as well as properties.
this. props - stores properties
this. state - stores state (can only be assigned in constructor, then modified with setState), state is often a counter
What is the component lifecycle in React?
Mounting - on ReactDOM.render or when added to parent
(After mounting: componentDidMount is called)
Updating - when props change or setState is called
(After updating: componentDidUpdate is called)
Unmounting - when removed from parent or DOM
(Before unmounting: componentWillUnmount is called)
What are props?
properties: immutable, defined where you call instance of a component
if parent changes, may pass different props to child causing it to re-render