The Jebel Irhoud Discovery
Earth — How Morocco's fossils reshaped human evolution
react component/ree-AKT KOM-poh-nent/
A JavaScript function that returns JSX (HTML-like syntax) instead of a conventional return value, permitting code reuse through the illusion of modularity while deferring the actual complexity to state management and prop threading.
Origin React: from the library's name, itself a shorthand for 'reactive programming.' Component: from Latin com- (together) and ponere (to place), originally meaning a constituent part. The word claims the pieces will fit together; the claim is optimistic.
The thing most people miss Most component reusability fails at the first prop that breaks the layout for another instance, revealing that the modular promise was always about hiding complexity rather than eliminating it.
See also //state management//
Prop drilling in action: data flows downward through every component whether it needs it or not
function UserProfile({ userId }) {
const [user, setUser] = React.useState(null);
const [loading, setLoading] = React.useState(true);
React.useEffect(() => {
fetch(`/api/users/${userId}`)
.then(res => res.json())
.then(data => {
setUser(data);
setLoading(false);
});
}, [userId]);
if (loading) return <div>Loading...</div>;
return (
<div className="profile">
<h1>{user.name}</h1>
<p>{user.email}</p>
<UserStats user={user} />
<UserBio user={user} />
<UserPosts user={user} />
</div>
);
}
// This component now passes `user` down through three more layers
// of child components that each need only one property from it.
// Refactoring requires touching files in four different folders.
