1.0.0 • Published 5 months ago

react-fake-data v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

šŸ“– React Fake Data (react-fake-data)

A lightweight React package to generate fake user data, posts, and profiles for testing and development.

šŸ“Œ Features:
āœ… Simple and easy-to-use hooks (useFakeUser, useFakePosts)
āœ… Pre-built FakeProfile component for quick UI testing
āœ… Uses faker-js/faker for realistic data generation
āœ… Supports customization for different data types


šŸš€ Installation

Install via npm:

npm install react-fake-data

or yarn:

yarn add react-fake-data

šŸ”„ Usage Guide

1ļøāƒ£ Generate Fake User Data (useFakeUser)

import React from "react";
import { useFakeUser } from "react-fake-data";

const UserDemo = () => {
  const user = useFakeUser();

  return (
    <div>
      <h2>Fake User</h2>
      <img src={user.avatar} alt="User Avatar" width="50" />
      <p>Name: {user.name}</p>
      <p>Email: {user.email}</p>
      <p>Phone: {user.phone}</p>
    </div>
  );
};

export default UserDemo;

šŸŽÆ Returns:

{
  id: "1a2b3c4d",
  name: "John Doe",
  email: "johndoe@example.com",
  avatar: "https://random-avatar.com/123",
  address: "123 Main St",
  phone: "+123456789"
}

2ļøāƒ£ Generate Fake Posts (useFakePosts)

import React from "react";
import { useFakePosts } from "react-fake-data";

const PostsDemo = () => {
  const posts = useFakePosts(3); // Generate 3 fake posts

  return (
    <div>
      <h2>Fake Posts</h2>
      {posts.map((post) => (
        <div key={post.id}>
          <h3>{post.title}</h3>
          <p>{post.content}</p>
          <p><strong>Author:</strong> {post.author}</p>
        </div>
      ))}
    </div>
  );
};

export default PostsDemo;

šŸŽÆ Returns:

[
  {
    id: "a1b2c3",
    title: "How to build a React App",
    content: "This is a tutorial on building React apps...",
    author: "Alice Doe",
    date: "2024-02-11T10:30:00.000Z"
  },
  ...
]

3ļøāƒ£ Fake Profile Component (<FakeProfile />)

import React from "react";
import { FakeProfile } from "react-fake-data";

const ProfileDemo = () => {
  return (
    <div>
      <h2>Fake Profile</h2>
      <FakeProfile />
    </div>
  );
};

export default ProfileDemo;

šŸŽÆ Renders a pre-built profile card with fake data.


āš™ API Reference

šŸ”¹ useFakeUser()

šŸ“Œ Returns: { id, name, email, avatar, address, phone }

šŸ”¹ useFakePosts(count = 5)

šŸ“Œ Params: count (number) → Number of fake posts to generate
šŸ“Œ Returns: [{ id, title, content, author, date }, ...]

šŸ”¹ <FakeProfile />

šŸ“Œ Description: Pre-built component that displays a fake user profile
šŸ“Œ Usage: <FakeProfile />