JSX Syntax
Which of the following best describes JSX in React?
- A markup language to write CSS inside JavaScript
- A type of JavaScript extension that lets you write XML-like code inside JS
- A tool for compiling JavaScript files to HTML
- A language to create custom HTML elements
- A sytnax for writing for loops in JS
Component State
How should you update the state of a class component in React?
- By assigning a value directly to this.state
- By calling this.setState() with the new state
- By using setProps method
- By changing the state from the render method
- By assigning values to props
Props vs State
What is the primary difference between props and state in React components?
- Props are immutable, state can change inside the component
- State is passed from parent to child, props are local to the component
- Props update automatically, state doesn’t change
- State is used only for class components, props are for functions
- Props are arrays only, state is an object only
PureComponent
What special behavior does a PureComponent implement in React?
- It only renders functional components
- It does a shallow comparison of props and state to avoid unnecessary re-renders
- It allows direct modification of props
- It always re-renders on every state update
- It disables all lifecycle methods
Event Handling
Which is a correct way to handle an event in a React element?
- Using onclick attribute
- onClick={this.handleClick}
- on-click='this.handleClick'
- onclick='handleClick()'
- onClick: this.handleClick
Keys in Lists
Why is the key prop important when rendering lists of elements in React?
- It helps style components more easily
- It tells React which elements have changed, are added, or are removed
- It is used to encrypt props
- It makes the render function pure
- It disables automatic re-rendering
Virtual DOM
What is the Virtual DOM in React?
- A server-side DOM implementation
- An in-memory representation of the actual DOM to optimize updates
- A type of CSS module
- A deprecated feature for form validation
- A real dom element managed by React
Redux Principles
Which of the following is NOT a core principle of Redux?
- Single source of truth
- State is read-only
- Changes are made with pure functions
- Components can directly mutate the store
- Actions describe state changes
Higher-Order Component
What is a Higher-Order Component (HOC) in React?
- A component that renders only on-demand
- A function that takes a component and returns a new component
- A special CSS class to style multiple components
- A prop with a function as its value
- A built-in HTML component available in React
Hooks Introduction
Starting from React 16.8, what feature allows function components to use state and other features?
- Reducers
- Mixins
- Hooks
- Refs
- Promises