Reusability / Patterns Flashcards

1
Q

Do this with react children…

[div]

[Navbar name=”yo” /]

[div]

A

[div]

[Navbar]

[p] This is where name goes [/p]

[/Navbar]

[/div]

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

What is the main case for using react children?

A

When you need to put much different information within the same component. If it’s too much for props to pass, you might want to insert data using it as props.children.

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

How do you access children?

A

Wrap the compenent tag with data…

[Component]

[p] This is the data [/p]

[/Component]

and access it within the Component like this…

{props.children}

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

What are examples of higher-order functions?

A

.map()

.filter()

.reduce()

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

What is the definition of a Higher Order Component? (HOC)

A

A function that takes a component as its first argument and returns a new component that wraps the given component, providing extra capabilities to it.

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

How to change a class based Component into a Functional Component?

A

class Menu extends Component {

render() {

return (

into

function Menu(props) {

return (

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

What is an example of using a HOC?

Higher Order Component

A

When you have two components that are using state for the same purpose, perhaps for true/false toggle.

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

What is a good example of a File Structure for HOC?

(higher order component?)

A

App.js

HOCs -> theNameOfHOC.js

(lowercase, camel)

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

What is the syntax of a basic HOC?

(Higher Order Component)

import {exampleHOC} from “./HOCs/exampleHOC”

[this component goes here]

export default exampleHOC(ComponentName)

– Calling the Function with Component as variable

A

import React from “react”

export function exampleHOC(component) {

return function(props) {

return (

<toggler></toggler>

)}}

— Toggler — is a classed based component used only in this…

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

Why are we learning HOCs?

What are the newer versions of HOCs?

A

Higher Order Components are more for legacy code. If you are writing newer code, you’re good.

Render Props - Still Legacy

Hooks - Newest and Shiniest

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