What is React? JSX Introduction and Your First Component
What problem React actually solves, how JSX syntax works, and how to build your first component.
A Higher-Order Component (HOC) is a function that takes a component and returns a new, enhanced component. It's an older, but still valid, pattern for reusing cross-cutting logic (loading states, auth checks, analytics).
function withLoading(WrappedComponent) {
return function WithLoadingComponent({ isLoading, ...props }) {
if (isLoading) {
return <p>Loading...</p>;
}
return <WrappedComponent {...props} />;
};
}
function UserList({ users }) {
return (
<ul>
{users.map(u => <li key={u.id}>{u.name}</li>)}
</ul>
);
}
const UserListWithLoading = withLoading(UserList);
// Usage:
<UserListWithLoading isLoading={loading} users={users} />
withLoading wrapped UserList in a new component that handles the loading logic itself — UserList has no idea this logic even exists.
function withAuth(WrappedComponent) {
return function WithAuthComponent(props) {
const { user } = useContext(AuthContext);
if (!user) {
return <Navigate to="/login" />;
}
return <WrappedComponent {...props} />;
};
}
const ProtectedDashboard = withAuth(Dashboard);
In modern React, custom hooks (like useAuth()) are often more readable and composable than HOCs for most cases — they also avoid "wrapper hell" (multiple nested HOCs). Still, the HOC pattern remains relevant in some libraries (like Redux's old connect()) and for JSX-level wrapping.
What problem React actually solves, how JSX syntax works, and how to build your first component.
Set up a modern React project in seconds with Vite, and understand the resulting folder structure.
Build functional components and pass data from parent to child components using props.