Brand Logo

The render props pattern allows you to share code between React components using a prop whose value is a function.

const DataFetcher = ({ url, render }) => {
  const [data, setData] = useState(null);
  const [loading, setLoading] = useState(true);
  
  useEffect(() => {
    fetch(url)
      .then(res => res.json())
      .then(data => {
        setData(data);
        setLoading(false);
      });
  }, [url]);
  
  return render({ data, loading });
};
Solsn Technologies | Web Develpment, Web Designing, App Development, Digital Marketing, React Development