linkedin-skill-assessments-quizzes

React.js

Q1. If you want to import just the Component from the React library, what syntax do you use?

Q2. If a function component should always render the same way given the same props, what is a simple performance optimization available for it?

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"))

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';

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);

Q6. What is the testing library most often associated with React?

Q7. To get the first item from the array (“cooking”) using array destructuring, how do you adjust this line?

const topics = ['cooking', 'art', 'history'];

Q8. How do you handle passing through the component tree without having to pass props down manually at every level?

Q9. What should the console read when the following code is run?

const [, , animal] = ['Horse', 'Mouse', 'Cat'];
console.log(animal);

10. What is the name of the tool used to take JSX and turn it into createElement calls?

11. Why might you use useReducer over useState in a React component?

12. Which props from the props object is available to the component with the following syntax?

<Message {...props} />

13. Consider the following code from React Router. What do you call :id in the path prop?

<Route path="/:id" />

14. 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'));

15. 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?");

16. What property do you need to add to the Suspense component in order to display a spinner or loading state?

function MyComponent() {
  return (
    <Suspense>
      <div>
        <Message />
      </div>
    </Suspense>
  );
}

17. What do you call the message wrapped in curly braces below?

const message = 'Hi there';
const element = <p>{message}</p>;

18. What can you use to handle code splitting?

19. When do you use useLayoutEffect?

20. What is the difference between the click behaviors of these two buttons (assuming that this.handleClick is bound correctly)?

A. <button onClick={this.handleClick}>Click Me</button>
B. <button onClick={event => this.handleClick(event)}>Click Me</button>

21. How do you destructure the properties that are sent to the Dish component?

function Dish(props) {
  return (
    <h1>
      {props.name} {props.cookingTime}
    </h1>
  );
}

22. When might you use React.PureComponent?

23. Why is it important to avoid copying the values of props into a component’s state where possible?

24. What is the children prop?

25. Which attribute do you use to replace innerHTML in the browser DOM?

26. Which of these terms commonly describe React applications?

27. When using webpack, why would you need to use a loader?

28. A representation of a user interface that is kept in memory and is synced with the “real” DOM is called what?

29. You have written the following code but nothing is rendering. How do you fix this problem?

const Heading = () => {
  <h1>Hello!</h1>;
};

Q30. To create a constant in JavaScript, which keyword do you use?

Q31. What do you call a React component that catches JavaScript errors anywhere in the child component tree?

Q32. In which lifecycle method do you make requests for data in a class component?

Q33. React components are composed to create a user interface. How are components composed?

Q34. All React components must act like **\_\_** with respect to their props.

Q35. Why might you use a ref?

Q36. What is [e.target.id] called in the following code snippet?

handleChange(e) {
  this.setState({ [e.target.id]: e.target.value })
}

Q37. What is the name of this component?

class Clock extends React.Component {
  render() {
    return <h1>Look at the time: {time}</h1>;
  }
}

Q38. What is sent to an Array.map() function?

Q39. Why is it a good idea to pass a function to setState instead of an object?

Q40. What package contains the render() function that renders a React element tree to the DOM?

Q41. How do you set a default value for an uncontrolled form field?

Q42. What do you need to change about this code to get it to run?

class clock extends React.Component {
  render() {
    return <h1>Look at the time: {this.props.time}</h1>;
  }
}
Explanation

In JSX, lower-case tag names are considered to be HTML tags. Read [this article](https://reactjs.org/docs/jsx-in-depth.html#html-tags-vs.-react-components)

Q43. Which Hook could be used to update the document’s title?

Q44. What can you use to wrap Component imports in order to load them lazily?

Q45. How do you invoke setDone only when component mounts, using hooks?

function MyComponent(props) {
  const [done, setDone] = useState(false);

  return <h1>Done: {done}</h1>;
}

Q46. What value of button will allow you to pass the name of the person to be hugged?

class Huggable extends React.Component {
  hug(id) {
    console.log("hugging " + id);
  }

  render() {
    let name = "kitteh";
    let button = // Missing Code
    return button;
  }
}

Q47. Currently, handleClick is being called instead of passed as a reference. How do you fix this?

<button onClick={this.handleClick()}>Click this</button>

Q48. Which answer best describes a function component?

Q49. Which library does the fetch() function come from?

Q50. What will happen when this useEffect Hook is executed, assuming name is not already equal to John?

useEffect(() => {
  setName('John');
}, [name]);

Q51. Which choice will not cause a React component to rerender?

Q52. You have created a new method in a class component called handleClick, but it is not working. Which code is missing?

class Button extends React.Component{

  constructor(props) {
    super(props);
    // Missing line
  }

  handleClick() {...}
}

Q53. React does not render two sibling elements unless they are wrapped in a fragment. Below is one way to render a fragment. What is the shorthand for this?

<React.Fragment>
  <h1>Our Staff</h1>
  <p>Our staff is available 9-5 to answer your questions</p>
</React.Fragment>
<...>
  <h1>Our Staff</h1>
  <p>Our staff is available 9-5 to answer your questions</p>
</...>
<//>
  <h1>Our Staff</h1>
  <p>Our staff is available 9-5 to answer your questions</p>
<///>
<>
  <h1>Our Staff</h1>
  <p>Our staff is available 9-5 to answer your questions</p>
</>
<Frag>
  <h1>Our Staff</h1>
  <p>Our staff is available 9-5 to answer your questions</p>
</Frag>

Q54. If you wanted to display the count state value in the component, what do you need to add to the curly braces in the h1?

class Ticker extends React.component {
  constructor(props) {
    super(props);
    this.state = { count: 0 };
  }
  render() {
    return <h1>{}</h1>;
  }
}

Q55. Per the following code, when is the Hello component displayed?

const greeting = isLoggedIn ? <Hello /> : null;

Q56. In the following code block, what type is orderNumber?

ReactDOM.render(<Message orderNumber="16" />, document.getElementById('root'));

Q57. You have added a style property to the h1 but there is an unexpected token error when it runs. How do you fix this?

const element = <h1 style={ backgroundColor: "blue" }>Hi</h1>;

Q58. Which function is used to update state variables in a React class component?

Q59. Consider the following component. What is the default color for the star?

const Star = ({ selected = false }) => <Icon color={selected ? 'red' : 'grey'} />;

Q60. Which answer best describes a function component?(Not sure answer)

Q61.Which library does the fetch() function come from?

Q62.What is the difference between the click behaviors of these two buttons(assuming that this.handleClick is bound correctly)

  A. <button onClick=this.handleClick>Click Me</button>
  B. <button onClick={event => this.handleClick(event)}>Click Me</button>

Q63.What will happen when this useEffect Hook is executed, assuming name is not already equal to John?

useEffect(() => {
  setName('John');
}, [name]);

Q64. How would you add to this code, from React Router, to display a component called About?

<Route path="/:id" />

Q65. Which class-based component is equivalent to this function component?

const Greeting ({ name }) > <h1>Hello {name}!</h1>;

Q66. Give the code below, what does the second argument that is sent to the render function describe?

ReactDOM.render(
  <h1>Hi<h1>,
    document.getElementById('root')
)

Q68. What is the first argument, x, that is sent to the createElement function?

React.createElement(x, y, z);

Q69. Which class-based lifecycle method would be called at the same time as this effect Hook?

useEffect(() => {
  // do things
}, []);

Q70. Given the code below, what does the second argument that is sent to the render function describe?

ReactDOM.render(
  <h1>Hi</h1>
  document.getElementById('root')
);

Q71. What is the first argument, x, that is sent to the createElement function?

React.createElement(x,y,z);