Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

357
Views
blog in React: how to merge two API calls

I want to build a simple blog where posts are fetched from https://jsonplaceholder.typicode.com/posts and users from https://jsonplaceholder.typicode.com/users but I am stuck with the following problem. I want to display author name next to the post but I don't know how to code it. Simply put I need to use IF from the JSON object from the call to https://jsonplaceholder.typicode.com/posts and according to the result display author name from the call to https://jsonplaceholder.typicode.com/users...

Here is the relevant piece of code:

import { useParams } from "react-router-dom";
import useFetch from "./useFetch";


const BlogDetails = () => {
  const { id } = useParams();
  const { data: blog, error, isPending } = useFetch('https://jsonplaceholder.typicode.com/posts/' + id);
  

 

  return (
    <div className="blog-details">
      { isPending && <div>Loading...</div> }
      { error && <div>{ error }</div> }
      { blog && (
        <article>
          <h2>{ blog.title }</h2>
          <p>Written by { blog.userId }</p>
          <div>{ blog.body }</div>
          <p>Comments: </p>
        </article>
        
      )}
    </div>
  );
}
 
export default BlogDetails;

The whole code is here: https://github.com/qubit4/react_blog

What I should put into "Written by: { }" instead of "blog.userId" to make it work?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!