-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreact-example.tsx
More file actions
34 lines (31 loc) · 909 Bytes
/
Copy pathreact-example.tsx
File metadata and controls
34 lines (31 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Illustrative React example — drop into any React + bundler setup
// (Vite, Next.js, CRA, etc.) after `npm install @sahinur/forgedata react`.
import { ForgeDataProvider, useGenerator } from "@sahinur/forgedata/react";
function UserCard({ userId }: { userId: string }) {
const user = useGenerator(
(forge) => ({
name: forge.person.fullName(),
email: forge.internet.email(),
avatar: forge.image.avatar(),
jobTitle: forge.person.jobTitle(),
}),
[userId],
);
return (
<div>
<img src={user.avatar} alt="" width={48} height={48} />
<p>
<strong>{user.name}</strong> — {user.jobTitle}
</p>
<p>{user.email}</p>
</div>
);
}
export default function App() {
return (
<ForgeDataProvider seed="react-example" locale="en">
<UserCard userId="user-1" />
<UserCard userId="user-2" />
</ForgeDataProvider>
);
}