linkedin-skill-assessments-quizzes

Q96. Which language can you not use with React?

Q97. This code is part of an app that collects Pokemon. How would you print the list of the ones collected so far?

constructor(props) {
    super(props);
    this.state = {
        pokeDex: []
    };
}

Reference

Q98. What would be the result of running this code?

function add(x = 1, y = 2) {
  return x + y;
}

add();

image

Explanation: function that called without parameter will use its param default value, thus x will always be default to 1 and y will always be default to 2.

Q99. Why might you use a React.ref?

Reference

Q100. What pattern is being used in this code block?

const { tree, lake } = nature;

Reference

Q101. How would you correct this code block to make sure that the sent property is set to the Boolean value false?

ReactDom.render(
  <Message sent=false />,
  document.getElementById("root")
);
<Message sent={false} />,
ReactDom.render(<Message sent="false" />, document.getElementById('root'));
<Message sent="false" />,
ReactDom.render(<Message sent="false" />, document.getElementById('root'));

Passing Props to a Component

Q102. This code is part of an app that collects Pokemon. The useState hook below is a piece of state holding onto the names of the Pokemon collected so far. How would you access the collected Pokemon in state?

const PokeDex = (props) => {
  const [pokeDex, setPokeDex] = useState([]);
  /// ...
};

Explanation: useState always return an array with two values, the state itself (on first value) and the set function that lets you update the state (on second value) useState Reference

Q103. What would you pass to the onClick prop that will allow you to pass the initName prop into the greet handler?

const Greeting = ({ initName }) => {
  const greet = (name) => console.log("Hello, " + name + "!");
  return <button onClick={ ... }>Greeting Button </button>
}

Explanation: Apparently the question misstyped greet as hug. Putting this aside, we can still learn from this question.

Q104. What is the name of the compiler used to transform JSX into JavaScript?

JSX Transform with Babel

Q105. Which hook is used to prevent a function from being recreated on every component render?

React Hooks useCallback docuementation

Q106. Why might you use the useRef hook?

Reference

Q107. Which of the following is required to use React?

Reference

Q108. What is the correct way to get a value from context?

Reference

Q109. Why is ref used?

Reference

Q110. Choose the method which should be overridden to stop the component from updating?

Reference

Q111. What is the functionality of a “webpack” command?

Q112. Choose the method which is not a part of ReactDOM?

Q113. In react, the key should be?

Reference

Q114. Which company developed ReactJS?

Reference

Q115. Choose the library which is most often associated with react?

Reference

Q116. What of the following is used in React.js to increase performance?

Reference

Q117. Among The following options, choose the one which helps react for keeping their data uni-directional?

Reference

Q118. Which choice is a correct refactor of the Greeting class component into a function component?

class Greeting extends React.Component {
  render() {
    return <h1>Hello {this.props.name}!<h1>;
  }
}

Q119. Why is the waitlist not updating correctly?

const Waitlist = () => {
  const [name, setName] = useState('');
  const [waitlist, setWaitlist] = useState([]);
  const onSubmit = (e) => {
    e.preventDefault();
    waitlist.push(name);
  };
  return (
    <div>
      <form onSubmit={onSubmit}>
        <label>
          Name: <input type="text" value={name} onChange={(e) => setName(e.target.value)} />
        </label>
        <button type="submit">Add to waitlist</button>
      </form>

      <ol>
        {waitlist.map((name) => (
          <li key={name}>{name}</li>
        ))}
      </ol>
    </div>
  );
};

Reference

Q120. What is the pattern that is used in the Context.Consumer below?

{(isLoggedIn)=>{isLoggedIn ? "Online" : "Offline"}}

Q121. In React.js which one of the following is used to create a class for Inheritance ?

Reference

Q122. What is the purpose of render() in React.js?

Reference

Q123. What is the use of super(props) in React.js?

Reference

Q124. What is Redux in React.js?

Reference

Q125. What is the purpose of the virtual DOM in React.js, and how does it improve performance in web applications??

Reference

Q126. You run the following code and get this error message: “invalid hook call.” what is wrong with the code?

import React from 'react';

const [poked, setPoked] = React.useState(false);

function PokeButton() {
  return <button onClick={() => setPoked(true)}>{poked ? 'You have left a poke.' : 'Poke'}</button>;
}

Q127. A colleague comes to you for help on a react component. They say that the poke button renders correctly, however when the button is clicked, this error is shown: “setPoked is not defined”. What is wrong with their code?

function PokeButton() {
  const { poked, setPoked } = useState(false);
  return <button onclick={() => setPoked(true)}>{poked ? 'You have left a poke.' : 'Poke'}</button>;
}

Q128. This component is loaded dynamically. What should you replace XXXX with to complete the code?

const OtherComponent = React.lazy(() => import('./OtherComponent.js'));

function MyComponent() {
  return (
    <XXXX fallback={<spinner />}>
      <OtherComponent />
    </XXXX>
  );
}

Q129. Elements in lists in React should have __ that are ___ .

Q130. You want to memorize a callback function so you ensure that React does not recreate the function at each render. Which hook would you use to accomplish this?

Source: CodeDamn

Q131. You want to perform a network operation as the result of a change to a component’s state named userInput. what would you replace XXXX with?

useEffect(callNetworkFunc, XXXX);

Q132. When is the Hello component displayed?

<div>{isLoggedIn ? <Hello /> : null}</div>

Q133. When do you use useLayoutEffect?

Q134. What is the difference between state and props in React?

Q135. Which language can you not use with React?

Q136. Which answer best describes a function component?

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

Q138. In React, what is the purpose of the key prop when rendering a list of components

Q139. What is the primary function of React Router?

Q140. When should you use Redux in a React application?

Q141. What is the use of React hooks?

Q142. How can you pass data through a React component tree without having to pass props down manually at every level?

Q143. What is React?

Reference React Overview

Q144. Which method is used to create a React component?

Reference Components and Props

Q145. What is JSX?

Reference Introducing JSX

Q146. What is the purpose of the useEffect hook?

Reference Using the Effect Hook

Q148. Which prop is used to pass data from parent to child components?

<ChildComponent name="John" age={25} />

Reference Components and Props

Q149. What is the correct way to handle events in React?

function Button() {
  const handleClick = () => {
    console.log('Button clicked');
  };

  return <button onClick={handleClick}>Click me</button>;
}

Reference Handling Events

Q150. Which lifecycle method is called after a component is mounted?

Reference Component Lifecycle

Q152. What is the correct way to update state in a class component?

Reference State and Lifecycle

Q153. What is the purpose of React.Fragment?

return (
  <React.Fragment>
    <h1>Title</h1>
    <p>Description</p>
  </React.Fragment>
);

Reference Fragments

Q155. Which method is used to prevent default behavior in React events?

Reference SyntheticEvent

Q156. What is the correct way to conditionally render elements in React?

function Greeting({ isLoggedIn }) {
  return <div>{isLoggedIn ? <h1>Welcome back!</h1> : <h1>Please sign up.</h1>}</div>;
}

Reference Conditional Rendering

Q157. Which hook is used for performance optimization by memoizing expensive calculations?

Reference useMemo Hook

Q158. What is the purpose of the useCallback hook?

Reference useCallback Hook

Q159. What is the correct way to pass a function as a prop?

function Parent() {
  const handleClick = () => console.log('Clicked');
  return <Child onClick={handleClick} />;
}

Reference Passing Functions to Components

Q161. Which statement about React components is correct?

Reference Components and Props

Q162. Which hook is used to reduce state management complexity?

Reference useReducer Hook

Q164. What is the correct way to handle forms in React?

function Form() {
  const [value, setValue] = useState('');

  const handleSubmit = (e) => {
    e.preventDefault();
    console.log(value);
  };

  return (
    <form onSubmit={handleSubmit}>
      <input value={value} onChange={(e) => setValue(e.target.value)} />
      <button type="submit">Submit</button>
    </form>
  );
}

Reference Forms

Q165. Which method is used to update state based on previous state?

setCount((prevCount) => prevCount + 1);

Reference Functional Updates

Q166. What is the purpose of React.memo?

Reference React.memo

Q167. Which hook is used to imperatively access DOM elements?

Reference Refs and the DOM

Q168. What is the correct way to handle asynchronous operations in useEffect?

useEffect(() => {
  const fetchData = async () => {
    const response = await fetch('/api/data');
    const data = await response.json();
    setData(data);
  };

  fetchData();
}, []);

Reference Effect Hook with Async

Q169. Which statement about React Hooks is correct?

Reference Rules of Hooks

Q170. What is the purpose of the dependency array in useEffect?

Reference Effect Dependencies

Q171. Which method is used to create a custom hook?

function useCounter(initialValue = 0) {
  const [count, setCount] = useState(initialValue);

  const increment = () => setCount(count + 1);
  const decrement = () => setCount(count - 1);

  return { count, increment, decrement };
}

Reference Building Your Own Hooks

Q172. What is the correct way to handle errors in React components?

Reference Error Boundaries

Q173. Which statement about React Context is correct?

Reference Context

Q174. What is the purpose of the useLayoutEffect hook?

Reference useLayoutEffect Hook

Q175. Which method is used to optimize performance by preventing unnecessary renders?

Reference Optimizing Performance

Q176. What is the correct way to pass multiple props to a component?

const props = { name: 'John', age: 25, city: 'New York' };
return <UserCard {...props} />;

Reference JSX Spread Attributes

Q177. Which hook is used to debug custom hooks?

Reference useDebugValue Hook

Q178. What is the purpose of React.StrictMode?

Reference Strict Mode

Q179. Which statement about React portals is correct?

Reference Portals

Q180. What is the correct way to handle component cleanup?

useEffect(() => {
  const timer = setInterval(() => {
    console.log('Timer tick');
  }, 1000);

  return () => {
    clearInterval(timer);
  };
}, []);

Reference Effect Cleanup

Q181. Which method is used to forward refs in React?

Reference Forwarding Refs

Q182. What is the purpose of the useImperativeHandle hook?

Reference useImperativeHandle Hook