Complete React.
js Notes for Interview Preparation
1. What is React?
- A JavaScript library for building user interfaces.
- Maintained by Meta (Facebook).
- Used to build Single Page Applications (SPAs).
2. Core Features
- JSX JavaScript + HTML syntax.
- Components Reusable UI blocks.
- Virtual DOM Optimized DOM manipulation.
- Unidirectional Data Flow One-way data binding.
- Declarative UI Describe what UI should look like.
3. Component Types
Functional Components (Modern)
function Hello({ name }) {
return <h1>Hello {name}</h1>;
Class Components (Legacy)
class Hello extends React.Component {
render() {
return <h1>Hello {this.props.name}</h1>;
}
4. Props vs State
Props: Passed from parent, Read-only, Available in Functional & Class components
State: Managed internally, Mutable, Only in stateful components
5. React Hooks (Functional Components)
useState:
const [count, setCount] = useState(0);
useEffect:
useEffect(() => {
console.log("Effect runs");
}, [dependency]);
useContext:
const value = useContext(MyContext);
Other Hooks: useRef, useMemo, useCallback, useReducer
6. Component Lifecycle (Class)
Mounting: constructor -> render -> componentDidMount
Updating: shouldComponentUpdate -> render -> componentDidUpdate
Unmounting: componentWillUnmount
7. React Router (v6)
Install: npm install react-router-dom
Usage:
<BrowserRouter>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/about" element={<About />} />
</Routes>
</BrowserRouter>
8. State Management
Lifting State Up: Share via parent
Context API:
const MyContext = React.createContext();
Redux (with Toolkit Recommended):
- Centralized store
- Actions -> Reducers -> State
- useSelector, useDispatch
9. Redux Toolkit Example
createSlice:
const counterSlice = createSlice({
name: 'counter',
initialState: 0,
reducers: {
increment: state => state + 1,
decrement: state => state - 1
});
10. List Rendering
items.map(item => <li key={item.id}>{item.name}</li>)
11. Conditional Rendering
isLoggedIn ? <Dashboard /> : <Login />
12. Form Handling
const handleChange = (e) => setName(e.target.value);
13. Styling Options
CSS, CSS Modules, Styled Components, Tailwind, Inline styles
14. Testing
Jest, React Testing Library
test('renders header', () => {
render(<App />);
expect(screen.getByText(/Hello/i)).toBeInTheDocument();
});
15. Performance Optimization
React.memo, useMemo, useCallback, Code splitting
16. Deployment
Build: npm run build
Deploy: Vercel, Netlify, Firebase, GitHub Pages
17. Common Interview Questions
- Difference between props and state?
- Explain virtual DOM.
- useEffect hook use cases?
- React performance optimization?
- Context API vs Redux?
- What is React.memo?
- Handling forms in React?
- Importance of keys in lists?
Bonus: Best Practices
- Keep components small
- Lift state up
- Avoid unnecessary re-renders
- Use keys in lists
- Avoid mutating state directly