React Flashcards

1
Q

Why use functional components over class based components?

A
  1. Less code
  2. Easier to understand
  3. Stateless
  4. Simpler to test
  5. No ‘this’ binding
  6. Easier to extract smaller components
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why should we keep our components small?

A
Small components are easier to:
Read
Test
Maintain
Reuse
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why use arrow functions when declaring methods in class based components?

A

In order to bind the this keyword to the class.

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

When should we use a function, rather than an object, in this.setState?

A

When the new state we want to set rely on the previous state.

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

What can the function we can pass to this.setState() take as arguments?

this.setState((?,?) => {

});

A

prevState, props

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

What is prop-types and what is its purpose?

A

It is an external library for typechecking props

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

How to use prop-types?

A

import PropTypes from ‘prop-types’

ComponentName.propTypes = {
name: PropTypes.string.isRequired
}

https://reactjs.org/docs/typechecking-with-proptypes.html

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