React Hooks Introducing React Hooks 2 — Questions and Answers
Question 1: In which React version were Hooks officially released as a stable feature?
- React 15.0
- React 16.8 (Correct answer)
- React 17.0
- React 18.2
Correct answer: React 16.8
Hooks were added to React in version 16.8.
Question 2: What is the primary problem Hooks were designed to solve regarding stateful logic?
- Slow rendering of large lists
- Difficulty reusing stateful logic between components (Correct answer)
- Inability to render SVG
- Lack of server-side rendering
Correct answer: Difficulty reusing stateful logic between components
Hooks make it easy to extract and share stateful logic without changing the component hierarchy.
Question 3: Which of these patterns did Hooks aim to replace for sharing logic?
- Higher-order components and render props (Correct answer)
- CSS modules
- Webpack loaders
- PropTypes
Correct answer: Higher-order components and render props
Hooks reduce the need for HOCs and render props by letting you reuse logic via custom Hooks.
Question 4: Can you use Hooks inside a class component?
- Yes, in any method
- Yes, only in the constructor
- No, Hooks only work in function components (Correct answer)
- No, Hooks only work in the render method
Correct answer: No, Hooks only work in function components
Hooks let you use state and other features without writing a class, and cannot be called inside classes.
Question 5: What naming convention identifies a function as a React Hook?
- It ends with 'Hook'
- It starts with the prefix 'use' (Correct answer)
- It is written in all caps
- It is prefixed with 'with'
Correct answer: It starts with the prefix 'use'
Hooks are functions whose names start with 'use', like useState and useEffect.
Question 6: Are Hooks backward-compatible with existing React code?
- No, they require a full rewrite
- Yes, they are completely opt-in and non-breaking (Correct answer)
- Only with a Babel plugin
- Only in new projects
Correct answer: Yes, they are completely opt-in and non-breaking
Hooks are 100% backward-compatible and contain no breaking changes.
Question 7: Which statement best describes the relationship between Hooks and classes?
- Hooks remove classes from React immediately
- Hooks provide a more direct API to React features without classes (Correct answer)
- Hooks require classes internally
- Hooks only work after converting classes
Correct answer: Hooks provide a more direct API to React features without classes
Hooks give a more direct API to props, state, context, refs, and lifecycle without classes.
In which React version were Hooks officially released as a stable feature?