title: State is not gatting update when using setstate in react with hooks
body: <p>I am facing an issue regarding the <em>setstate</em>. I want to do the following steps:</p>
  <ol>
  <li>I m fetching some blogs from the server.</li>
  <li>Adding blogs data to blogs state</li>
  <li>Filtering a blog that is the same as URL param</li>
  <li>Adding that blog to blog state</li>
  </ol>
  <p>problem is coming at stape 4 when I am trying to add that particular blog to the blog state. When I am logging both states, the blog state is coming as empty array [].</p>
  <pre><code>function BlogDetail(props) {
    const [blog, setBlog] = useState([]);
    const [blogs, setBlogs] = useState([]);
  
    let param = useParams();
  
    // Fetch blogs from server
    const getBlogs = () =&gt; {
      axios
        .get(&quot;/blog/all_blog/&quot;)
        .then((res) =&gt; {
          setBlogs(res.data);
          console.log(res.data);
        })
        .catch((err) =&gt; console.log(err));
    };
  
    const getBlog = () =&gt; {
      const FixURL = (url) =&gt;
        url
          .replace(/[^a-zA-Z ]/g, &quot;&quot;)
          .replace(/\s+/g, &quot;-&quot;)
          .toLowerCase();
      setBlog(blogs.filter((artical) =&gt; FixURL(artical.title) === param.id));
    };
  
    useEffect(() =&gt; {
      getBlogs();
      getBlog();
    }, []);
  
    console.log(blog);
    console.log(blogs);
  
    return &lt;&gt;...&lt;/&gt;;
  }
  </code></pre>
  <p>I also tried to warp this setBlog into callback function but does work for me, not gatting why the blog state is gating updated.</p>
  <p>Thanks in Advance :)</p>