React - ENG - Linkedin Flashcards
Q1. If you want to import just the Component from the React library, what syntax do you use?
import React.Component from ‘react’
import [ Component ] from ‘react’
import Component from ‘react’
import { Component } from ‘react’
import { Component } from ‘react’
Q2. If a function component should always render the same way given the same props, what is a simple performance optimization available for it?
Wrap it in the React.memo higher-order component.
Implement the useReducer Hook.
Implement the useMemo Hook.
Implement the shouldComponentUpdate lifecycle method.
Wrap it in the React.memo higher-order component.
Q3. How do you fix the syntax error that results from running this code?
const person =(firstName, lastName) => { first: firstName, last: lastName } console.log(person("Jill", "Wilson"))
Wrap the object in parentheses.
Call the function from another file.
Add a return statement before the first curly brace.
Replace the object with an array.
Wrap the object in parentheses.
Q4. If you see the following import in a file, what is being used for state management in the component?
import React, {useState} from ‘react’;
React Hooks
stateful components
math
class components
React Hooks
Q5. Using object literal enhancement, you can put values back into an object. When you log person to the console, what is the output?
const name = 'Rachel'; const age = 31; const person = { name, age }; console.log(person);
{{name: “Rachel”, age: 31}}
{name: “Rachel”, age: 31}
{person: “Rachel”, person: 31}}
{person: {name: “Rachel”, age: 31}}
{name: “Rachel”, age: 31}
Q6. What is the testing library most often associated with React?
Mocha
Chai
Sinon
Jest
Jest
Q7. To get the first item from the array (“cooking”) using array destructuring, how do you adjust this line?
const topics = [‘cooking’, ‘art’, ‘history’];
const first = ["cooking", "art", "history"] const [] = ["cooking", "art", "history"] const [, first]["cooking", "art", "history"] const [first] = ["cooking", "art", "history"]
const [first] = [“cooking”, “art”, “history”]
Q8. How do you handle passing through the component tree without having to pass props down manually at every level?
React Send
React Pinpoint
React Router
React Context
React Context
Q9. What should the console read when the following code is run?
const [, , animal] = [‘Horse’, ‘Mouse’, ‘Cat’];
console.log(animal);
Horse
Cat
Mouse
undefined
Cat
Q10. What is the name of the tool used to take JSX and turn it into createElement calls?
JSX Editor
ReactDOM
Browser Buddy
Babel
Babel
Q11. Why might you use useReducer over useState in a React component?
when you want to replace Redux
when you need to manage more complex state in an app
when you want to improve performance
when you want to break your production app
when you need to manage more complex state in an app
Q12. Which props from the props object is available to the component with the following syntax?
Message {…props}
any that have not changed
all of them
child props
any that have changed
all of them
Q13. Consider the following code from React Router. What do you call :id in the path prop?
тег Route path=”/:id” тег
This is a route modal
This is a route parameter
This is a route splitter
This is a route link
This is a route parameter
Q14. If you created a component called Dish and rendered it to the DOM, what type of element would be rendered?
function Dish() { return h1 Mac and Cheese h1; } ReactDOM.render(тег Dish тег , document.getElementById('root'));
div
section
component
h1
h1
Q15. What does this React element look like given the following function? (Alternative: Given the following code, what does this React element look like?)
React.createElement(‘h1’, null, “What’s happening?”);
h1 props={null} What’s happening? h1
h1 What’s happening? h1
h1 id=”component” What’s happening? h1
h1 id=”element” What’s happening? h1
h1 What’s happening? h1