DEV Community

Discussion on: Why You Should Be Writing React Custom Hooks

Collapse
 
ganeshshetty195 profile image
Ganesh Shetty

import { useState, useEffect } from "react";
const CustomUtil = (url) => {
    const [data, setData] = useState(null);
    useEffect(() => {
        fetch(url)
            .then((res) => res.json())
            .then((data) => setData(data));
    }, [url]);
    return [data];
};

export default CustomUtil;

`this is a plain function with hooks in it
Enter fullscreen mode Exit fullscreen mode