Skip to content
ldfMion edited this page Mar 9, 2024 · 7 revisions

Hooks

useData

This React hook fetches comments from a placeholder JSON file (./placeholder.json). It then sorts the filtered comments in descending chronological order (newest first).

Returns: An array of posts in descending cronological order

usePostData

This React hook fetches posts from a placeholder JSON file (./placeholder.json) and filters them based on the provided id. It returns the first matching post or undefined if no post is found.

Parameters:

id (string): The unique identifier of the post to retrieve.

Returns:

Object | undefined: An object representing the matching post if found. undefined if no post matches the provided id. Usage:

useUserData

This React hook fetches user data from a placeholder JSON file (./placeholder.json).

Returns: Object: An object representing the user data from the JSON file.

useComments

This React hook fetches comments from a placeholder JSON file (./placeholder.json) and filters them based on the provided blog post id. It then sorts the filtered comments in descending chronological order (newest first).

Parameters:

postId (number): The unique identifier of the post for which to retrieve comments. Returns: Array<Object>: An array of comment objects matching the specified id, sorted by date (newest first). If no comments match the id, an empty array is returned.

Data schema:

Post

{
    title: string
    content: string
    author: string (name for now, maybe we will use an ID later)
    date: string (ISO format)
    id: string
    likes: number
}

User

{
    name: string
}

Comment

{
    "post": "c6d5e4f3",
    "author": "DavidLee",
    "likes": 14,
    "id": "u8v9w0x1",
    "date": "2023-04-22T16:15:00.000Z",
    "content": "Thanks for answering my questions!"
}

(I don't really know how to document data schema, so if anyone knows a better way, please change it)

Clone this wiki locally