score:1

import React from 'react';

const cache = {};

function useApi(id) {
  const [data, setData] = React.useState(null);

  React.useEffect(() => {
    if (cache[id]) {
      // if the data is already in the cache
      // use the cache
      setData(cache[id])

    } else {
      // do you api here 
      fetch("your api call here")

      // after the data is fetched.
      // update your cache
      cache[id] = data;
      // update your state
      setData(data);
    }
  }, [id, setData]);

  return data;
}

Related Query

More Query from same tag