The Hector Portfolio blog logic is split cleanly between a data layer (Documentation Index
Fetch the complete documentation index at: https://mintlify.com/iwinser117/react-portafolio/llms.txt
Use this file to discover all available pages before exploring further.
BlogService) and a React layer. The React layer lives in two files: src/hooks/useBlog.js, which exports five hooks (useBlog, useBlogPost, useBlogFilter, useBlogCategories, and useBlogTags) for fetching and filtering posts, and src/hooks/useComments.js, which exports one hook for managing comment submission. Together they provide every piece of state a blog component needs — loading indicators, error messages, and the data itself — without any component knowing how BlogService works internally.
Hooks in src/hooks/useBlog.js
useBlog()
Fetches the full list of blog posts on component mount by calling BlogService.getAllPosts().
Signature
loadingstarts astrueand flips tofalseonce theBlogServicecall settles (resolved or rejected).- On success,
postsis populated with the sorted array anderroris set tonull. - On failure,
postsis reset to[]anderrorholds the thrownError.messagestring. - The
useEffecthas an empty dependency array, so the fetch runs exactly once per mount.
useBlogPost(slug)
Fetches a single post by its slug whenever the slug value changes.
Signature
The URL-safe slug string that identifies the post. Typically sourced from
useParams(). The fetch is skipped if slug is falsy — useful when the param has not yet resolved.poststarts asnulland is populated after a successful fetch.- If
BlogService.getPostBySlugthrows (e.g.'Post no encontrado'),postis reset tonullanderrorreceives the message. - The effect re-runs whenever
slugchanges, making it safe to use on dynamic routes.
useBlogFilter(posts, filters)
Applies one or more filters to an existing array of posts. This hook is synchronous — it uses useMemo internally and has no side effects or async calls.
Signature
The source array to filter. Typically the
posts array returned by useBlog().Exact-match filter on
post.category. Posts that do not match are removed.Array of tag strings. A post passes this filter if any of the provided tags appears in
post.tags.Case-insensitive substring search applied to
post.title and post.excerpt. Tags are not searched by this hook (unlike BlogService.searchPosts).category → tags → search. A post must pass every active filter to appear in the result.
Example
useBlogCategories()
Fetches the deduplicated list of categories from BlogService.getCategories() on mount.
Signature
- Calls
BlogService.getCategories()once on mount (emptyuseEffectdependency array). categoriesstarts as[]and is populated after the 200 ms simulated delay resolves.- On error,
categoriesremains[]anderrorholds the message string.
useBlogTags()
Fetches the deduplicated list of all tags from BlogService.getTags() on mount.
Signature
- Calls
BlogService.getTags()once on mount. tagsstarts as[]and is filled with the flattened, deduplicated tag list after the 200 ms delay.- On error,
tagsremains[]anderrorholds the message string.
useComments Hook (src/hooks/useComments.js)
Comment submission logic lives in its own file: src/hooks/useComments.js. It exports a single hook.
useComments(slug)
Manages local comment state and the async submission flow for a specific post.
Signature
Slug of the post whose comments are being managed. Passed through to
BlogService.addComment.Local array of comments submitted during this session. Starts empty — you should seed it with the post’s existing
comments array via setComments after fetching the post.React state setter. Use this to initialise the local list with the post’s
comments once the post has loaded.Calls
BlogService.addComment(slug, commentData), prepends the returned Comment to the local comments array on success, and sets success to true for 3 seconds. Rethrows on failure so the calling component can react.true only while addComment is in-flight. Starts as false — unlike the blog-fetch hooks, this hook does not fetch on mount.Holds the error message if
BlogService.addComment throws (e.g. validation failures such as 'El nombre es requerido').Set to
true for 3 seconds after a successful addComment call, then automatically reset to false. Useful for showing a confirmation banner.Resets
error to null. Call this when the user starts typing to dismiss an inline error message.Manually resets
success to false before the 3-second timer fires.Comments added via
addComment are prepended to the local comments array immediately (optimistic-style) but are not persisted — they exist only for the current session. In production, connect BlogService.addComment to a backend endpoint that writes to a database, then re-fetch the post’s comment list to reflect the saved state.