title: Сustom data upload hook
body: <p>I wrote a simple code that requests data from a local json server when the page loads. I have this code repeated in several places and I want to put it in the custom hook.</p>
  <p>Tell me how to write and apply a custom hook correctly?</p>
  <pre><code>  const [data, setData] = useState()
  
    useEffect(() =&gt; {
      const getPosts = async () =&gt; {
        try {
          setData(await getData('http://localhost:3001/posts'))
        } catch (error) {
          console.log('ERROR &gt;&gt;', error.message)
        }
      }
      getPosts()
    }, [])
  </code></pre>
  <p>I tried to write like this, but it doesn't work:</p>
  <pre><code>import { useEffect, useState } from &quot;react&quot;
  import { getData } from './../helpers'
  
  const useData = url =&gt; {
  
    const [currentData, setCurrentData] = useState()
  
    useEffect(() =&gt; {
      const getCurrentData = async () =&gt; {
        try {
          setCurrentData(await getData(url))
        } catch (error) {
          console.log('ERROR &gt;&gt;', error.message)
        }
      }
      getCurrentData()
    }, [url])
    
    return currentData
  }
  
  export default useData
  </code></pre>