W7. ReactJS Flashcards

1
Q

What issues are there with AJAX?

A

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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a Model-View-Controller (MVC)

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is reactive programming?

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is functional programming?

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is functional reactive programming?

A

Create chains of higher order functions where updates are made automatically along chain when input values change (pipelines of data transformations).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are Pure Views in ReactJS?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is ReactJS?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is JSX?

A

Extension of Javascript with XML-like literals

- makes react more like HTML when rendering DOM elements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the virtual DOM?

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the two ways to define new types of component in ReactJS?

A
  • 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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are stateful components?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the component lifecycle in React?

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are props?

A

properties: immutable, defined where you call instance of a component
if parent changes, may pass different props to child causing it to re-render

How well did you know this?
1
Not at all
2
3
4
5
Perfectly