NEW
Font size
WorksheetsReact Fundamentals Assessment
Total questions: 20
Worksheet time: 10mins
What are props in React?
Props are methods for managing state.
Props are lifecycle hooks in React.
Props are styles applied to components.
Props in React are inputs to components that allow data to be passed and shared between them.
How do you pass props to a component?
You can only pass props using state management libraries.
Props cannot be passed to functional components.
Use JSX attributes to pass props, e.g.,
Use CSS to style the component directly.
What is prop validation in React?
Prop validation is a method to optimize performance.
Prop validation is only for class components.
Prop validation is used to manage state in React.
Prop validation in React is the process of checking the types and shapes of props passed to components using PropTypes.
Which library is commonly used for prop validation?
ReactDOM
Axios
Redux
PropTypes
What is the purpose of useState in React?
The purpose of useState in React is to manage state in functional components.
To handle side effects in functional components.
To create class components in React.
To manage routing in a React application.
How do you initialize state using useState?
const state = useState(initialValue);
const [state, setState] = useState(initialValue);
const [state, setState] = useState();
const [state, setState] = useState({});
What is destructuring in JavaScript?
Destructuring is a method for creating new objects in JavaScript.
Destructuring is a syntax for extracting values from arrays or properties from objects into variables.
Destructuring is a way to define functions in JavaScript.
Destructuring refers to the process of merging two arrays into one.
How can you destructure props in a functional component?
You can only access props directly without destructuring: function MyComponent(props) { ... }
You can destructure props by using the spread operator: const { ...props } = props;
You can destructure props by using function parameters like this: function MyComponent({ prop1, prop2 }) { ... }.
Destructuring props is not possible in functional components.
What is the difference between state and props?
Props are local to a component; state is passed from child to parent.
State and props are the same and can be used interchangeably.
State is mutable and local to a component; props are immutable and passed from parent to child.
State is always immutable; props can be changed by the component.
How do you update state using useState?
Use the updater function from useState: setState(newValue) or setState(prevState => newValue).
Use a global state management library instead.
Directly modify the state variable.
Use the useEffect hook to update state.
What is the default value of state when using useState?
true
0
undefined
null
Can you pass functions as props in React?
No, functions cannot be passed as props in React.
Yes, you can pass functions as props in React.
Only class components can receive functions as props.
Functions can only be passed as props in functional components.
What is the purpose of the PropTypes library?
To style React components effectively.
To manage state in React applications.
To enhance the performance of React components.
To validate the types of props passed to React components.
How do you define default props for a component?
Use the 'defaultProps' property on the component to define default values for props.
Use a separate configuration file for default props.
Use the 'props' property to set default values for props.
Define default props inside the component's constructor.
What happens if a required prop is not passed?
The component may fail to render correctly or throw an error.
The component will automatically fill in default values.
The prop will be ignored and have no effect.
The application will run without any issues.
How can you handle state updates based on previous state?
Directly modify the state variable without using a function.
Reset the state to its initial value every time.
Use a state updater function that takes the previous state as an argument to derive the new state.
Use a random value to set the new state.
What is the significance of the useEffect hook?
The useEffect hook is used for styling components.
The useEffect hook handles user input events.
The useEffect hook is for managing state in class components.
The useEffect hook manages side effects in functional components.
How do you conditionally render components based on state?
Only render components based on props, ignoring state.
Use a single component for all states without conditions.
Use conditional statements in the render method to return components based on state.
Render all components regardless of state.
What is the difference between functional and class components?
Class components are simpler and easier to read.
Functional components are always stateful.
Functional components can use lifecycle methods.
Functional components are stateless and simpler, while class components can manage state and lifecycle methods.
How can you optimize performance in a React application?
Implement code splitting, use React.memo, optimize rendering, and lazy load resources.
Use inline styles for all components
Avoid using hooks in functional components
Render all components at once without optimization
