How to create a piece that brings data from 2 url’s via fecth api?

Asked

Viewed 21 times

0

I have 2 API addresses below, and I need to create a React card that brings the first API photo, and the second API post.

https://jsonplaceholder.typicode.com/photos/ https://jsonplaceholder.typicode.com/posts

componentDidMount() {
  fetch('https://jsonplaceholder.typicode.com/users')
  .then(response=> response.json())
  .then(users => {this.setState({ post: users})});
}
render() {
    const { post, searchfield } = this.state;
    const filteredPost = post.filter(post =>{
        return post.name.toLowerCase().includes(searchfield.toLowerCase());
})
    return (
        <div className="App">
            <h1 style={{ textAlign: 'center'}}>
                Busca de Posts
            </h1>
            <Buscador searchChange={this.onSearchChange} />
            <div className='wrapper'>
                <UserList post={filteredPost} />
            </div>
        </div>
    );
}
  • Make two requests and join the results, what’s the problem?

  • I don’t know how to put the results together... , would that be right? Let Apidois = ['https://jsonplaceholder.typicode.com/users', 'https://jsonplaceholder.typicode.com/posts'] componentDidMount();}

  • You need to analyze the Apis and see what data the two have in common to use in the union

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.