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
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Discussion on: Why You Should Be Writing React Custom Hooks
Replies for: You have mentioned, you can't call a hook (like useEffect) in an ordinary helper function that is declared outside of a component But we can call ...
For further actions, you may consider blocking this person and/or reporting abuse