React Flashcards

Learn about react fundamental s

1
Q

Which if the following is used when adding an event to a button in react?
A onClick
B. onclick

A

onClick

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

What is the convention of defining a class in react?

A
Use lowercase for class 
the class extends component 
You normally states to access or modify  properties values.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the correct method of declaring a class name for a JSX element?

A

Use className

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

How do you add and output dynamic content within a react function.

A

Use the curly braces and or props

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

What is a restriction faced in react JSX

A

Class is reserved

You advised to only have one route element per component.

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

Can you change states directly?

A

No, it is immutable. Use setState to change state and notify dom

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

Can you change states directly?

A

No, it is immutable. Use setState to change state and notify dom

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

True or false. The function element found in setState merges the changes with the old state.

A

False

The function used in the hook usestate does not merge. It creates a new state.

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

What are the two ways in can modify the Dom in react?

A

state taken from react component

and props which use Hooks

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

What is a example of react Hook?

A

useState

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

What is the difference in the way states and hooks handle other state data?

A

In classes that use state , any changes made are merged with previous state.
In functions props which use Hooks, the state creates new state so you need to include this change in function that changes state.

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

What is React.createElement?

A

Method for rendering JSX , Takes the following arguments: an element which is rendered to the Dom, configuration other wise a object, then children or what will be nested in side the elements.

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

How can one render iteration in react

A

JavaScript provides a array method Array.protoype.map which can be used render an array of objects.

Syntax let new array = array.map( funct callback( current Value, [, index [, array]] { return element of new array }[ , thisArg])

const arrayx = [ 1 , 2 , 3 , 4 ]
const map1 = arrayx.map( x => x + 1 )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

When is it not ideal to use map()

A

When you are not using the returning array , not returned a value from callback.

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

How would you attempt to handle JavaScript errors beyond your control , like server request.

A

You can wrap your code using error boundaries class. This return a message in production mode.

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

How can you run locally scoped class names for CSS styles that are easy to identify without adding complexity with naming conventions.

A

You can use CSS modules .
React V2,, + -require you add modules in the name using [name]. module.css

Older version require ejection and modifications

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

What are error boundaries?

A

Error boundaries are react components that handle JavaScript errors by catching them in their child components tree. Allowing you to log errors and display fall back UI rather than let the UI crash.
A component becomes a errorBoundary when it defines either or both getDerivedStateFromError or componentDidCatch lifecycle methods.

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

How does React monitor changes in state in the mapping of React arrays

A

Map has key which can provide unique identifier for each element in the state array.

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

What are the benefits of spread operators in Rest state management?

A

Spread operators can be used when setting state in order to avoid directly updating the original state object.

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

What is the purpose of the restructuring in useState and hooks?

A

useState uses restructuring to split array into current state and the function to set state.

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

What are the benefits of using arrow functions in react components callbacks.

A

Arrow functions have a key feature that shares same lexical ‘ this ‘ as surrounding code. It does not require the literal use of binding with ‘this’ operators unlike function.

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

Snipet “rce” means

A

Create a customisation react class component.

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

Snipet “rafcp” means

A

Create a react function component with props

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

Snipet rafce means

A

Create a react arrow function component

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

Snipet rfce means

A

create a react function component

25
Q

Snipet “rcc” means

A

Create a default react class component

26
Q

Snipet ‘rfc’ means

A

Create a default react function component

27
Q

Snipet ‘imrs’ means

A

Import react and useState hook

28
Q

Snipet ‘est’ means

A

create an empty state object.

29
Q

Snipet ‘sst’ means

A

create an empty setState method call.

30
Q

Snipet ‘bnd’ means

A

create a method referencing binding

31
Q

snipet ‘nfn’ means

A

create an arrow function

32
Q

What is advantage of using errorboundaries

A

They catch errors during rendering, lifecycle methods and constructors in tree below them. They do not catch errors in UI

33
Q

What are the main life-cycles for updating react

A

shouldComponentUpdate(nextProp , nextstate)

34
Q

How do you include dependencies in useEffect hook

A

You include an array of dependencies i.e useEffect(()=>{//effect code },[//dependencies]);

35
Q

What happens when you have a useEffect with an empty array of dependencies?

A

It will only run the effect in useEffect once.

36
Q

What are the rules of using hooks?

A

It must be used in top levels of function. i.e not in loops, conditions or inner functions.
Secondly, it hooks should be called from react function, or created hook not javascript function.

37
Q

How can you optimise class based react component?

A

shouldComponentUpdate(nextProps , nextSTate) can be monitored to see if there are changes after render() by comparing the nextProps with current or this.props. This only works provided you create a copy of state of the state array , otherwise you will be comparing to current pointer.

38
Q

How can you optimise functional based react component.

A

use react.memo

39
Q

How can you optimise functional based react component.

A

use react.memo
Wrap react.memo around component code to be used.
default export React.memo(function)

40
Q

What is the benefit of using higher order component.

A

It can be used to handle cross-cutting concerns. It can be used as a abstraction that allows us to define reused logic in a single place and share it across many components. HOC adds an wrapping class which adds additional functionality. It takes a function and returns a new component.

41
Q

What is HOC

A

It is a design pattern, higher-order component (HOC) is an advanced technique in React for reusing component logic.

42
Q

Why must you not modify the original components prototype.

A

modifying the original component or mutating code inside HOC , can result in clashes. the consumer must know how they are implemented in order to avoid conflicts with other HOCs. Therefore use compositions instead. ( wrapping the input component in a container )component:

43
Q

What is the purpose of proptypes in react?

A

proptypes provide type checking ensuring the right value is being assigned.

44
Q

How may one access unknown props in higher order components?

A

Using the withnameofclass you can access jsx with wrappedcomponent and then use destructuring to extract the individual props.

45
Q

What are refs in react?

A

Ref is an technique used to modify props in situations where parent needs to interact with child components. ref can be created in the constructor using React.createRef() or by using callback refs { } (i.e ref pass a function with its containing component as an argument) . These work only in class components. For functional you use hook useRef and reference useRef()

46
Q

What is context?

A

It is a way of handling prop chain problems by a way to pass data through the component tree without having to pass props down manually at every level.

47
Q

What is context API?

A

It is a way of handling prop chain problems by providing a way to pass data through the component tree without having to pass props down manually at every level.

48
Q

What is signature of useState hook?

A

Array [current state , setStatefunction] = useState( initvalue)

49
Q

Where should you use setState function?

A

Use it in callback function used in JSX reference. Value to trigger

50
Q

What is as a prop , and how is it used?

A

While you are able to pass down information from parent to child via props, to pass information from child to parent you need to create a callback prop in form of a function with the named reference element as a property in the child element.

51
Q

What is axios?

A

It is a promised based HTTP client used for dealing XMLHttpRequests and Node interface for both on Node and web browser through its API. It is useful tool for interfacing web with REST API .

52
Q

How do you use axios?

A

Use axios GET request through promise axios.get( “URL”).then(function(response){

// Handle success
Console.log(response)
}).catch(  function (error)){ 
  // Manage failure
  Console.log(response)
}
)
53
Q

When should you use componentDidUpdate?

A

Use it when there is side effect in your web app , such as an update to component or props change which isn’t called for initial render. But only for Dom update.

54
Q

What is suggested to address performance issues in componentDidUpdate?

A

At risk of looping update and rendering a condition is added to check change of state between prevState and this.state.

55
Q

True or False: Props are readonly

A

True, a component should never modify its own props.

56
Q

How do you render a React Element

A

You first must pass DOM element to ReactDOM.createRoot()
then you pass the react element to root.render()

57
Q

why is a DIV in REACT regarded as a root DOM?

A

DIV is a root DOM node because everything inside it will be managed by React DOM.

58
Q

What is react fibre?

A

react uses react fiber to reconcile the fiber tree or DOM tree. A fiber is a JavaScript object, a unit of work. It represents a node of the DOM tree, or a React element, and contains data about a component. The react core uses a reconciler (algorithm) to identify which elements are to be rendered after certain changes are made by the developer, it does this by comparing two DOMS and diff’ing them. React fiber is a new reconciler with backward compatibility.

59
Q

What is the purpose of imrd snippet?

A

Importing reactDOM

60
Q

What is the purpose of the imbr snippet

A

Importing browser router

61
Q

What I the purpose of a browser router?

A

Everything to be routed should be held there. It has property to render content according to a defined path or route a component to a defined path.