CS220 Final Spring23-1
CS220 Final Spring23-1
3. Can a child component pass data back to its parent component using props?
A. Yes, child components can pass data back to the parent using props.
B. No, props can only be passed from parent to child, not vice versa.
C. Only functional components can pass data back to the parent.
D. It depends on the specific use case and component implementation.
4. Which of the following is the correct way to access a prop named name inside a React
component?
A. props.name
B. component.props.name
C. name.value
D. state.props.name
6. How can you pass an initial value to the state when using functional components with React
Hooks?
2
7. In React, what is a callback handler?
8. How can you pass a callback handler from a parent component to a child component in
React?
10. How do you declare a state variable using the useState hook?
12. How do you update the state using the useState hook?
A. setCount(newValue);
B. count = newValue;
C. setState(newValue);
D. setState({ count: newValue });
A. Improved performance.
B. Simplicity of implementation.
C. Better control and synchronization of input values.
D. Automatic form validation.
3
14. What are side effects in React?
A. useEffect
B. useState
C. useReducer
D. useContext
16. When does the side effect code inside the useEffect hook run?
17. Which of the following is a common use case for the useEffect hook?
20. What is the benefit of using object destructuring for props in React?
4
21. Which syntax is used to perform object destructuring in the component function signature?
A. function MyComponent(props) {}
B. function MyComponent({ prop1, prop2 }) {}
C. function MyComponent([prop1, prop2]) {}
D. function MyComponent({ prop1: value1, prop2: value2 }) {}
22. How can you provide default values for destructured props in the component function
signature?
23. What is the advantage of using object destructuring in the component function signature?
5
28. In React, what is an inline handler?
31. How does an inline handler differ from a callback handler in React?
34. What is the recommended approach for handling complex logic in inline event handlers?
A. Inline event handlers should only be used for simple, concise functions.
B. Complex logic should be handled within separate event handler functions.
C. Inline event handlers support any level of complexity and are suitable for all scenarios.
D. Complex logic should be avoided in React components altogether.
6
35. How do you pass parameters to an inline event handler?
39. Which of the following methods can be used for conditional rendering in React?
A. Ternary operator.
B. if-else statements.
C. Logical && operator.
D. All the above.
40. What is the syntax of the ternary operator in React conditional rendering?
41. What is the purpose of the condition in the logical AND operator (&&) for conditional
rendering?
7
42. What is the correct way to conditionally render content based on a state value in React?
B. if(stateValue==='condition'){
return<div>Content</div>;
}
C. <RenderIf condition={stateValue ==='condition'}>
<div>Content</div>
</RenderIf>
D. return stateValue === 'condition' ? <div>Content</div> : null;
44. Which of the following statements is true about handling errors with the `fetch` function in
React?
45. What is the correct and concise way to use the `fetch` function to make a GET request in
React?
fetch(url, {
method: 'GET'
A. })
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
fetch.get(url)
B. .then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
fetch(url)
C. .then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
fetch(url)
.get()
D.
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
8
46. Which of the following is an example of implicit search in React?
A. Using the `isLoading` prop and a conditional statement in the component's render
method.
B. Using the `setTimeout` function to delay the rendering of the loading indicator.
C. Adding a CSS class to the component when loading is in progress.
D. Wrapping the component with a higher-order component that handles the loading state.
49. What is the recommended approach for displaying error messages to users in React?
50. Which of the following statements is true when fetching asynchronous data in React using
hooks?
A. The useEffect hook with an empty dependency array is used to fetch data once when
the component mounts.
B. The useEffect hook with a dependency array containing the data variable is used to
fetch data whenever the data changes.
C. The useEffect hook with a dependency array containing an empty object is used to fetch
data on every component re-render.
D. The useEffect hook is not suitable for fetching asynchronous data in React.