React Concepts Summary
React Concepts Summary
---
1. Virtual DOM
- Lightweight copy of the real DOM.
- React updates the real DOM efficiently by comparing changes in the virtual DOM.
- Example:
```javascript
const element = <h1>Hello, Virtual DOM!</h1>;
ReactDOM.render(element, document.getElementById('root'));
```
---
2. Hooks
### Core Hooks
- **useState**: Manage state.
```javascript
const [count, setCount] = useState(0);
```
---
3. Lifecycle Methods
#### Updating
- **shouldComponentUpdate**: Optimize rendering.
- **componentDidUpdate**: Triggered after updates.
```javascript
componentDidUpdate(prevProps) {
if (prevProps.value !== this.props.value) {
console.log("Value updated");
}
}
```
#### Unmounting
- **componentWillUnmount**: Cleanup tasks.
```javascript
componentWillUnmount() {
console.log("Component will unmount");
}
```
---
4. Redux Key Concepts
### Example
- **Store**: Holds the state.
```javascript
const store = createStore(reducer);
```
- **React-Redux**:
- **useSelector**: Access state.
```javascript
const count = useSelector((state) => state.counter);
```
- **useDispatch**: Dispatch actions.
```javascript
const dispatch = useDispatch();
dispatch(increment());
```
---
This summary provides an overview of React's core features with examples. For
detailed implementations, use the snippets in actual projects.