mirror of
https://github.com/lainbo/component-party.git
synced 2026-04-05 13:09:03 +08:00
23 lines
556 B
JavaScript
23 lines
556 B
JavaScript
import { useState, createContext } from "react";
|
|
import UserProfile from "./UserProfile";
|
|
|
|
const UserContext = createContext();
|
|
|
|
export default function App() {
|
|
// In a real app, you would fetch the user data from an API
|
|
const [user, setUser] = useState({
|
|
username: "unicorn42",
|
|
email: "john@example.com",
|
|
});
|
|
|
|
function updateEmail(newEmail) {
|
|
setUser((userData) => ({ ...userData, email: newEmail }));
|
|
}
|
|
|
|
return (
|
|
<UserContext.Provider value={{ ...user, updateEmail }}>
|
|
<UserProfile />
|
|
</UserContext.Provider>
|
|
);
|
|
}
|