Working example in here.

const App = () => {
  const [myApi, setMyApi] = useState([]);
  const [data, setData] = useState([]); // add your data to here
  const [currentPage, setCurrentPage] = useState(1);
  const [postsPerPage] = useState(10);
  const [searchUser, setSearchUser] = useState("");

  useEffect(() => {
    fetch("https://randomuser.me/api/?results=50")
      .then(data => data.json())
      .then(json_result => {
        setData(json_result.results);  // set your data to state
        let myApi = renderData(json_result.results);  // render your component
        setMyApi(myApi); // set it to state
      });
  }, []);

  const renderData = (data) => {
     return data.map((item, idx) => {
            return (
              <div key={idx}>
                <img src={item.picture.thumbnail} alt="" /> {item.name.first}
                <hr />
              </div>
            );
          });
  }

  // get current post
  const indexOfLastPost = currentPage * postsPerPage; // 1 * 10 = 10
  const indexOfFirstPost = indexOfLastPost - postsPerPage; // 10 - 10 = 0
  const currentPosts = myApi?.slice(indexOfFirstPost, indexOfLastPost); // 0 to 10

  // search users by user input
  const handleSearchInput = event => {
    setSearchUser(event.target.value);
    const newData = renderData(data.filter(item => item.name.first.toLowerCase().includes(event.target.value)));  // render filtered data
    setMyApi(newData); // and set it to state
  };

  const paginate = pageNumber => setCurrentPage(pageNumber);

  return (
    <div>
      <Search onChange={handleSearchInput} />
      <Pagination
        postsPerPage={postsPerPage}
        totalPosts={myApi?.length}
        paginate={paginate}
      />
      {currentPosts}
    </div>
  );
};

const Search = ({ onChange }) => {
  return (
    <div>
      <input
        type="text"
        autoFocus={true}
        placeholder="search users"
        onChange={onChange}
      />
    </div>
  );
};
Answer from Rajitha Udayanga on Stack Overflow
🌐
GitHub
github.com › suttonj06 › random-user-api-react
GitHub - suttonj06/random-user-api-react: Utilize Random User API with ReactJS
Utilize Random User API with ReactJS. Contribute to suttonj06/random-user-api-react development by creating an account on GitHub.
Author   suttonj06
🌐
YouTube
youtube.com › coding shiksha
React Fetch API Random User API Example | HTTP Requests in React - YouTube
Buy the full source code of application here:https://buy.stripe.com/4gwcQ66FbeFa8jC4xbSubscribe for more Videos: https://www.youtube.com/channel/UCR6d0EiC3G4...
Published   February 19, 2020
Views   10K
🌐
CodePen
codepen.io › moscow › pen › XYmxBE
React + randomuser api example (old)
class Counter extends React.Component { constructor() { super(); this.state = { pictures:[], } } componentDidMount() { fetch('https://randomuser.me/api/?results=100') .then(results =>{ return results.json(); }).then(data => { let pictures = ...
🌐
CodeSandbox
codesandbox.io › s › randomuser-api-in-react-rkoqp
Randomuser API in React - CodeSandbox
June 24, 2019 - Randomuser API in React by katarzyna-stepczynska using react, react-dom, react-scripts
Published   Jun 23, 2019
Author   katarzyna-stepczynska
🌐
DEV Community
dev.to › dileno › react-sample-app-with-api-call-and-update-to-latest-version-30cl
React Sample App with API Call and Update to Latest Version - DEV Community
September 20, 2019 - You can find the React app on my GitHub: hello-react · I have a RandomUser component which simply looks like this: We fetch a user from the API and present the user's name and picture, if present.
Top answer
1 of 2
2

Working example in here.

const App = () => {
  const [myApi, setMyApi] = useState([]);
  const [data, setData] = useState([]); // add your data to here
  const [currentPage, setCurrentPage] = useState(1);
  const [postsPerPage] = useState(10);
  const [searchUser, setSearchUser] = useState("");

  useEffect(() => {
    fetch("https://randomuser.me/api/?results=50")
      .then(data => data.json())
      .then(json_result => {
        setData(json_result.results);  // set your data to state
        let myApi = renderData(json_result.results);  // render your component
        setMyApi(myApi); // set it to state
      });
  }, []);

  const renderData = (data) => {
     return data.map((item, idx) => {
            return (
              <div key={idx}>
                <img src={item.picture.thumbnail} alt="" /> {item.name.first}
                <hr />
              </div>
            );
          });
  }

  // get current post
  const indexOfLastPost = currentPage * postsPerPage; // 1 * 10 = 10
  const indexOfFirstPost = indexOfLastPost - postsPerPage; // 10 - 10 = 0
  const currentPosts = myApi?.slice(indexOfFirstPost, indexOfLastPost); // 0 to 10

  // search users by user input
  const handleSearchInput = event => {
    setSearchUser(event.target.value);
    const newData = renderData(data.filter(item => item.name.first.toLowerCase().includes(event.target.value)));  // render filtered data
    setMyApi(newData); // and set it to state
  };

  const paginate = pageNumber => setCurrentPage(pageNumber);

  return (
    <div>
      <Search onChange={handleSearchInput} />
      <Pagination
        postsPerPage={postsPerPage}
        totalPosts={myApi?.length}
        paginate={paginate}
      />
      {currentPosts}
    </div>
  );
};

const Search = ({ onChange }) => {
  return (
    <div>
      <input
        type="text"
        autoFocus={true}
        placeholder="search users"
        onChange={onChange}
      />
    </div>
  );
};
2 of 2
1

Since you're useEffect has [] (empty array) as the dependency, you're user fetching logic will only be called once i.e. on the initial rendering. You can add searchUser as useEffect's dependency so you can fetch users whenever the searchUser text changes.

🌐
Stack Overflow
stackoverflow.com › questions › 65444356 › how-to-get-user-details-of-user-from-randomuser-api
How to get user details of user from randomuser API?
import React, {useState, useEffect} from 'react' import { useParams } from 'react-router-dom'; export const UserDetail = () => { const {userid} = useParams() const [result, setResult] = useState([]); useEffect(() => { fetch(`/user-detail/${userid}`).then(res=>res.json()).then(result=> { console.log(result) setResult(result); }) }, []) return ( <div> </div> ) } ... Here is another free API you can use instead if you are interested in generating random users with details.
🌐
GitHub
gist.github.com › aerrity › 53a7f710fcf4e78228de477b48a1259f
react-50-random-users-solution.js · GitHub
react-50-random-users-solution.js · This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters ·
Find elsewhere
🌐
Random User Generator
randomuser.me
Random User Generator | Home
A free, open-source API for generating random user data. Like Lorem Ipsum, but for people.
🌐
Sololearn
code.sololearn.com › WnBUV4ek7kBN
HTML/CSS - React.js + Random User API Online Editor and JavaScript ...
Use our FREE HTML/CSS/JavaScript online editor to write, run and share your code. Works directly from your browser without any additional installation.
🌐
GeeksforGeeks
geeksforgeeks.org › reactjs › build-a-random-user-generator-app-using-reactjs
Build a Random User Generator App Using ReactJS - GeeksforGeeks
July 24, 2024 - The use­Effect hook is employed to fe­tch user data from a random user API when the­ component mounts.
🌐
YouTube
youtube.com › watch
Javascript Fetch API Example – Build a Random User Generator App - YouTube
Buy the full source code of application here:https://buy.stripe.com/dR6dUa1kR9kQdDWbZ0
Published   January 19, 2019
🌐
CodePen
codepen.io › KristofferTroncoso › pen › JvyWbz
Profile Cards (React, Random-User-API)
ct.Component { static defaultProps = { name: 'Bob', email: 'default@email.com', pic: 'default.jpg' } getNewUser = e => { fetch('https://randomuser.me/api/') .then(response => response.json()) .then(data => { let firstName = data.results[0].name.first[0].toUpperCase() + data.results[0].name.first.slice(1); let lastName = data.results[0].name.last[0].toUpperCase() + data.results[0].name.last.slice(1); let name = firstName + ' ' + lastName; let email = data.results[0].email; let pic = data.results[0].picture.large; let username = data.results[0].login.username; this.props.gettingUser({name, email
🌐
GitHub
github.com › topics › random-users-api
random-users-api · GitHub Topics · GitHub
A React application that displays cat facts paired with random user profiles, featuring infinite scroll pagination and real-time data fetching. react typescript cat-api tailwindcss random-users-api
🌐
GitHub
github.com › topics › randomuser-api
randomuser-api · GitHub Topics · GitHub
This website is created using React JS. The data used is fetch from https://randomuser.me/api/ .
🌐
RapidAPI
rapidapi.com › guides › build-random-user-generator-app
How to build a Random User Generator App using ...
Guides by Rapid offer short and long form API Development content with interactive examples and visuals to help you become a pro API Developer.
🌐
GitHub
github.com › damarendra › react-native-random-user-app
GitHub - damarendra/react-native-random-user-app: Fetch and Display API from randomuser.me/api
Fetch and Display Random User from https://randomuser.me/api/ { "axios": "^0.18.0", "prop-types": "^15.7.2", "react": "16.6.3", "react-native": "0.58.5", "react-native-elements": "^1.1.0", "react-native-gesture-handler": "^1.0.16", "react-native-vector-icons": "^6.3.0", "react-navigation": "^3.3.2", "react-redux": "^6.0.1", "redux": "^4.0.1", "redux-actions": "^2.6.4", "redux-saga": "^1.0.2", "reselect": "^4.0.0" }
Author   damarendra