mirror of
https://github.com/lainbo/component-party.git
synced 2026-04-05 13:09:03 +08:00
25 lines
583 B
JavaScript
25 lines
583 B
JavaScript
import { useState } from "react";
|
|
import UserProfile from "./UserProfile";
|
|
import { UserContext } from "./UserContext";
|
|
|
|
export default function App() {
|
|
const [user, setUser] = useState({
|
|
id: 1,
|
|
username: "unicorn42",
|
|
email: "unicorn42@example.com",
|
|
});
|
|
|
|
function updateUsername(newUsername) {
|
|
setUser((userData) => ({ ...userData, username: newUsername }));
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<h1>Welcome back, {user.username}</h1>
|
|
<UserContext.Provider value={{ ...user, updateUsername }}>
|
|
<UserProfile />
|
|
</UserContext.Provider>
|
|
</>
|
|
);
|
|
}
|