React Flashcards

1
Q

Why did you choose React?

A
  • Quick and easy setup with minimal code
  • State makes program reactive, props make data flow easy
  • Component based architecture- allows you to break complex UI into simple reusable components
  • Virtual DOM makes for faster and more efficient apps
  • JSX make it easy to include HTML
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the major features of React?

A
  • Speed, efficiency, flexibility
  • JSX
  • Virtual DOM
  • Component-based architecture
  • Declarative UI(as opposed to imperative-step by step)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

State vs Props

A
  • State is component data managed *within the component that *mutates, mostly from user events
  • Similar to variables declared within a function
  • Re-renders component on state change (makes application “reactive’)
  • Props are component data/functions received from *above and are *immutable(on receiving end)
  • Similar to function parameters (components configurations/options)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the virtual DOM? How does the virtual DOM work?

A
  • Virtual representation of UI that is kept in memory and synced with the actual DOM by a library like React-Dom - process is called Reconciliation
  • Enables declarative API of react
  • Whenever a change is made in the application, the 2 are compared and only the components that have changed are updated. This makes for a more efficient application both speed wise and storage wise.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is JSX?

A

“Syntactic sugar”

  • Syntax extension to Javascript used with React to describe what UI should look like, produces React ‘elements’
  • Allows you to write dynamic HTML in JS easily, very verbose in vanilla JS

-Babel is used to transpile JSX to JS so that browser can execute it

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

What does lifting state up mean and why do we do it?

A
  • Lifting state up means updating state in a parent component based on an event triggered by a child component.
  • We do this to create a single source of truth so multiple child components can have access to the same state variables that are managed in the parent component
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Why do we set a key property when we map over an array in React?

A
  • Keys provide a stable identity with a unique identifier when creating lists
  • Used to identify which items have changed, or been added/removed enabling React to recycle existing DOM elements, thus providing a performance boost
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How does React use closures?

A

-React uses closures in hooks such as useEffect to update state variables.

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

How do you send data up from child to parent component?

A
  • Via callback functions passed down as props

- Call the function in the child component and pass the data as arguments

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

What are React Hooks?

A
  • Hooks allow functional components to hook into react features like state and lifecycle methods
  • useState: tracks state
  • useEffect: perform side effects like fetch data or update DOM
  • useContext: used to manage state globally
  • useRef: track state changes or access DOM element without causing re-render
  • useReducer: similar to useState but for complex logic
  • useCallback: returns a memoized callback(optimization technique)
  • useMemo: returns a memoized value
  • custom hooks: reusable function like fetch
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

React Ref…

A
  • Refs are variables that allow you to persist data between renders, but unlike state variables, updating refs does not cause a re-render.
  • Commonly used to store reference to DOM elements.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Why do we use React Dev Tools?

A
  • Good for debugging. Shows you component props/state/hooks
  • Inspector shows React component tree that builds the page
  • Profiler tab allows you to record an interaction
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Common approaches for styling React…

A
  • CSS classes
  • Inline CSS
  • Pre-processors(Sass, Stylus, Less)
  • CSS-in-JS Modules(Styled-components, Emotion, Styled-jsx)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Performance optimization strategies for React…

A
  • lazy loading is used to reduce the load time of your app
  • useMemo is a React hook used for caching CPU-Expensive functions, allowing it to only be called when needed. useCallback can be used for similar result
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the Strict Mode component used for?

A

Provides additional visibility of potential issues in components. Helps to find deprecated lifecycle methods and legacy patterns to ensure that React components follow current best practices.

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

What are synthetic events in React?

A

Synthetic events combine browser native events into one API, ensuring that events are consistent across different browsers.

ex.) e.preventDefault() on handleClick event

17
Q

What are Portals in React?

A

Portal is a way to render children into a DOM node that exists outside the DOM hierarchy of its parent component.

18
Q

Higher-order function:

A

A function that takes a component and returns a new component.