Font size
WorksheetsReact Quiz
Total questions: 18
Worksheet time: 23mins
What is JSX in React?
A JavaScript library
A syntax extension for JavaScript
A CSS framework
A database language
Which hook is used to manage state in a functional component?
useEffect
useRef
useState
useContext
Props in React are:
Mutable
Immutable
Stored in state
Used only in class components
What does useEffect run by default?
Only once
On every render
Only on state change
Only on props change
Which method is used to render a list in React?
for
forEach
map
reduce
What is the correct key rule in list rendering?
Keys should be random
Keys should be index always
Keys should be unique
Keys are optional
Which hook is used to share data globally?
useState
useEffect
useContext
useRef
Controlled components store input values in:
DOM
LocalStorage
React state
Props
Which is NOT a valid way to conditionally render in React?
Ternary operator
&& operator
if inside JSX
Logical operators
Why is key important in React lists?
Styling
Faster API calls
Efficient re-rendering
Form validation
What is the difference between props and state?
Props are read-only and passed from parents; state is mutable and managed within the component
Props are mutable and internal; state is external to the component
Both props and state are immutable and serve the same purpose
State is passed from parents; props are managed internally
Explain controlled vs uncontrolled components.
Controlled components manage input values through React state; uncontrolled components rely on native DOM inputs accessed via refs
Controlled components store values in LocalStorage; uncontrolled components sync with Redux
Controlled components are class-based; uncontrolled components are functional
Controlled components use useEffect; uncontrolled components use useContext
When should you use useEffect with an empty dependency array?
When you need the effect to run only once after the component mounts
When you need the effect to run on every render
When the effect should run only when props change
When the effect should run only on state updates
In a React functional component that displays a list of products, which array method should you use to return JSX for each product?
map
reduce
forEach
filter
For a simple React form using useState with one input field and a submit handler, which pattern correctly manages the input and submission?
Use onChange to update state for the input value and onSubmit to prevent default and process the state
Use useEffect to manage the input and submit without state
Use an uncontrolled input with refs and no submit handler
Store the input directly in LocalStorage on each keystroke and rely on default browser submission
What is map() function in javascript and explain what it actually does ?
( explanation with example is required)
Write the syntax of useState Hook ?
Write a function enclosed in a setTimeout function which will run an api ( https://dummyjson.com/posts ) to fetch only the posts over views > 300 .
