<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Batuhan San on Medium]]></title>
        <description><![CDATA[Stories by Batuhan San on Medium]]></description>
        <link>https://medium.com/@batusan?source=rss-630f65f72641------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Gpz1ya1NEADofM94DO0XtA.jpeg</url>
            <title>Stories by Batuhan San on Medium</title>
            <link>https://medium.com/@batusan?source=rss-630f65f72641------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 21:17:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@batusan/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[React Hooks — Creating Custom Hooks]]></title>
            <link>https://batusan.medium.com/react-hooks-creating-custom-hooks-a5b0716fb7f5?source=rss-630f65f72641------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5b0716fb7f5</guid>
            <category><![CDATA[web]]></category>
            <category><![CDATA[custom-hook]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[hooks]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Batuhan San]]></dc:creator>
            <pubDate>Wed, 13 Apr 2022 12:26:28 GMT</pubDate>
            <atom:updated>2022-04-13T12:36:23.601Z</atom:updated>
            <content:encoded><![CDATA[<h3>React Hooks — Creating Custom Hooks</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FBrsDQsNwGnV1ZhWNccvew.png" /></figure><p>I would like to tell you a little bit about why you should use Custom hooks. For example, You created a dashboard and you have hundreds of charts and graphical diagrams that can be toggle on and off. Are you sure you want to copy paste to anywhere that uses this feature? It would be bad practice if the same feature had to be used all over the place all the time.</p><blockquote>Now here’s why custom hook is important and how it makes things easier.</blockquote><p>We will now look at how Hooks solve many of the same problems without forcing you to add more components to the tree.</p><h4><strong>- Creating Custom Hook</strong></h4><p>A custom Hook is a JavaScript function whose name starts with ”use” and that may call other Hooks. For example, useToggle below is our first custom Hook:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cv0EwTXMsA_dmAhTx6zJzQ.png" /><figcaption>Toggle Hook</figcaption></figure><p>There’s nothing new inside of it — the logic is copied from the components above. Just like in a component, make sure to only call other Hooks unconditionally at the top level of your custom Hook.</p><h4>- Use Case</h4><p>In the beginning, our stated goal was to remove the duplicated logic from the tables and diagrams. Both of them want to toggle feature..</p><p>Now that we’ve extracted this logic to a useToggle hook, we can <em>just use it:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pvp4GE0zOfnofsqFNFtWmw.png" /></figure><h4><strong>- And Voila!</strong></h4><p>Here is such an easy and code readability feature.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fnice-bartik-9kr8nb%3Ffontsize%3D14%26hidenavigation%3D1%26theme%3Ddark&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fnice-bartik-9kr8nb%3Ffontsize%3D14%26hidenavigation%3D1%26theme%3Ddark&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2F9kr8nb%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ad0caa5e99525d89c2890c9996b85bf/href">https://medium.com/media/7ad0caa5e99525d89c2890c9996b85bf/href</a></iframe><h4>Conclusion</h4><p>As seen in the code example, using hooks to encapsulate shared logic is a good start, but we can keep exploring more.</p><p><a href="https://usehooks.com/">Use Hooks</a> , Also don’t forget to check out this site with hundreds of custom hooks.</p><h4><strong>Useful links</strong></h4><ul><li><a href="https://reactjs.org/docs/hooks-custom.html">React Documentation</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5b0716fb7f5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>