Pros of React:
Cons of React:
React is one of the most popular libraries for creating user interfaces. It has both strengths and weaknesses that should be considered when choosing technology.
React uses Virtual DOM to optimize UI updates:
// React efficiently updates only necessary parts
function UserList({ users }) {
return (
<ul>
{users.map(user => (
<li key={user.id}>
{user.name} - {user.status}
</li>
))}
</ul>
);
}
// When one user changes
// React updates only that element
React encourages creating reusable components:
// Universal button component
function Button({ type = 'primary', onClick, children }) {
return (
<button className={`btn btn-${type}`} onClick={onClick}>
{children}
</button>
);
}
// Use in different places
<Button onClick={save}>Save</Button>
<Button type="secondary" onClick={cancel}>Cancel</Button>
React has a huge community and many libraries:
// Popular libraries in React ecosystem
import { useState } from 'react'; // Built-in hook
import { BrowserRouter } from 'react-router-dom'; // Routing
import { Provider } from 'react-redux'; // State management
import styled from 'styled-components'; // Styling
React allows describing how the interface should look:
// Declarative approach
function TodoList({ todos }) {
return (
<ul>
{todos.map(todo => (
<li className={todo.completed ? 'done' : ''}>
{todo.text}
</li>
))}
</ul>
);
}
// Instead of imperative (without React)
// document.createElement, appendChild, etc.
Need to learn many concepts:
// Many technologies to learn
function ComplexComponent() {
const [state, setState] = useState();
const data = useContext(DataContext);
const memoizedValue = useMemo(() => computeExpensiveValue(a, b), [a, b]);
const debouncedCallback = useCallback(() => {}, []);
const [value, setValue] = useReducer(reducer, initialState);
// ... and many other hooks
}
React changes often, need to keep up with updates:
// What was relevant a year ago may be outdated
// React.createClass -> ES6 classes -> functional components
// PropTypes -> TypeScript
// componentWillReceiveProps -> getDerivedStateFromProps
React is only a UI library, everything else needs additions:
// Need many libraries for a full application
import { BrowserRouter, Route, Switch } from 'react-router-dom'; // Routing
import { Provider, useSelector, useDispatch } from 'react-redux'; // State
import axios from 'axios'; // HTTP
import { useQuery } from 'react-query'; // Queries
React and its ecosystem can increase application size:
# Example bundle size
react: ~40KB
react-dom: ~100KB
react-router: ~30KB
redux: ~20KB
Total: ~190KB (before compression)
✅ Good fit:
❌ Better not to use:
Conclusion: React is a powerful tool with many advantages, but its use should be justified. When applied correctly, it significantly simplifies the development of complex interfaces.