frontend-opensource-project / use-react-hooks

React hoooooooks😎
https://frontend-opensource-project.github.io/use-react-hooks/
5 stars 0 forks source link

[URH-70] useMockData μ‹ κ·œ #56

Closed jeongbaebang closed 2 months ago

jeongbaebang commented 2 months ago

πŸ‘Ύ Pull Request

1️⃣ Spec

2️⃣ λ³€κ²½ 사항

3️⃣ μ˜ˆμ‹œ μ½”λ“œ

import React from 'react';
import useMockData from './hooks/useMockData';

const App = () => {
  const { mockData, addItem } = useMockData({
    schema: {
      user: {
        id: 'UUID',
        name: 'string',
        age: 'number',
        address: ['string', 'string'],
        profilePicture: 'image',
        registrationDate: 'date',
        isAdmin: 'boolean',
        inventory: {
          money: 'number',
          connectionUser: [
            {
              userId: 'UUID',
              name: 'string',
              isActive: 'boolean',
              address: ['string', 'number'],
            },
          ],
        },
      },
    },
    options: {
      count: 5, // Initial number of mock data items
      type: {
        name: { min: 5, max: 15 },
        number: { min: 1, max: 100 },
        image: {
          width: { min: 400, max: 800 },
          height: { min: 300, max: 600 },
        },
        date: {
          start: '2022-01-01',
          end: '2023-01-01',
        },
      },
    },
  });

  return (
    <div>
      <h1>Mock Data Example</h1>
      <button onClick={addItem}>Add New Item</button>
      <ul>
        {mockData.map((item, index) => (
          <li key={index}>
            <div>
              <strong>ID:</strong> {item.user.id}
            </div>
            <div>
              <strong>Name:</strong> {item.user.name}
            </div>
            <div>
              <strong>Age:</strong> {item.user.age}
            </div>
            <div>
              <strong>Address:</strong> {item.user.address.join(', ')}
            </div>
            <div>
              <strong>Profile Picture:</strong>
            </div>
            <img
              src={item.user.profilePicture}
              alt="Profile"
              style={{ width: '100px', height: '100px' }}
            />
            <div>
              <strong>Registration Date:</strong>{' '}
              {item.user.registrationDate.toDateString()}
            </div>
            <div>
              <strong>Admin:</strong> {item.user.isAdmin ? 'Yes' : 'No'}
            </div>
            <div>
              <strong>Inventory:</strong>
            </div>
            <div>
              <strong>Money:</strong> {item.user.inventory.money}
            </div>
            <div>
              <strong>Connection Users:</strong>
            </div>
            <ul>
              {item.user.inventory.connectionUser.map(
                (connection, connIndex) => (
                  <li key={connIndex}>
                    <div>
                      <strong>User ID:</strong> {connection.userId}
                    </div>
                    <div>
                      <strong>Name:</strong> {connection.name}
                    </div>
                    <div>
                      <strong>Active:</strong>
                      {connection.isActive ? 'Yes' : 'No'}
                    </div>
                    <div>
                      <strong>Address:</strong> {connection.address.join(', ')}
                    </div>
                  </li>
                )
              )}
            </ul>
          </li>
        ))}
      </ul>
    </div>
  );
};

export default App;

4️⃣ κ΄€λ ¨ λ¬Έμ„œ (선택 사항)