<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Elizabeth</title>
    <description>The latest articles on DEV Community by Elizabeth (@ilizette).</description>
    <link>https://dev.to/ilizette</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F187170%2Fefb92216-7bac-4c77-96f7-d687875f6053.png</url>
      <title>DEV Community: Elizabeth</title>
      <link>https://dev.to/ilizette</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ilizette"/>
    <language>en</language>
    <item>
      <title>How to build an accessible tab</title>
      <dc:creator>Elizabeth</dc:creator>
      <pubDate>Tue, 12 Aug 2025 09:30:00 +0000</pubDate>
      <link>https://dev.to/ilizette/how-to-build-an-accessible-tab-1nom</link>
      <guid>https://dev.to/ilizette/how-to-build-an-accessible-tab-1nom</guid>
      <description>&lt;p&gt;When building web components, it's always a good idea to use the native HTML elements available. However, there are times when you may need to create custom components. In such cases, it's crucial to ensure that those components behave like their native counterparts, especially when it comes to accessibility.&lt;/p&gt;

&lt;p&gt;For example, when creating a custom button, you'd need to add the role="button" ARIA attribute to mimic the native &lt;code&gt;&amp;lt;button&amp;gt;&lt;/code&gt; element. Beyond that, you'd also want to ensure the component responds to keyboard interactions, such as the Enter or Space keys, to activate the button. This also includes setting up things like tabindex, managing focus, and handling other accessibility considerations.&lt;/p&gt;

&lt;p&gt;This tutorial, however, isn't about building custom buttons, it's about building a tab component. As of writing, there's no native HTML element specifically for tabs, making it essential to implement ARIA roles and behavior to make the component accessible.&lt;/p&gt;

&lt;p&gt;In this guide, I'll walk you through how to create an accessible tab component from scratch. The full code is available on &lt;a href="https://codepen.io/leezee/pen/jEbwyWv" rel="noopener noreferrer"&gt;Codepen&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisite
&lt;/h3&gt;

&lt;p&gt;To follow along with this tutorial, you'll need knowledge of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Basic HTML, CSS, and JavaScript knowledge&lt;/li&gt;
&lt;li&gt;ARIA&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ARIA Authoring Practices (APG)
&lt;/h3&gt;

&lt;p&gt;When I need to build components that aren't available as native HTML elements, I typically check the ARIA Authoring Practices Guide (APG) to review the accessibility considerations for the component. In this case, we'll be looking at the &lt;a href="https://www.w3.org/WAI/ARIA/apg/patterns/tabs/" rel="noopener noreferrer"&gt;Tabs Pattern.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The APG outlines the roles we'll be using for our tab component:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://w3c.github.io/aria/#tablist" rel="noopener noreferrer"&gt;Tablist&lt;/a&gt;: A list of tab elements that reference corresponding tabpanel elements.&lt;br&gt;
&lt;a href="https://w3c.github.io/aria/#tab" rel="noopener noreferrer"&gt;Tab&lt;/a&gt;: A label that provides a mechanism for selecting the tab content that will be displayed.&lt;br&gt;
&lt;a href="https://w3c.github.io/aria/#tabpanel" rel="noopener noreferrer"&gt;Tabpanel&lt;/a&gt;: A container for the content associated with a tab, where each tab is linked to its respective tabpanel.&lt;/p&gt;

&lt;p&gt;The APG also specifies key ARIA attributes for each role:&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt;The &lt;strong&gt;tablist&lt;/strong&gt; SHOULD include an &lt;code&gt;aria-labelledby&lt;/code&gt; attribute if the list has a visible label, or an &lt;code&gt;aria-label&lt;/code&gt; if it doesn't.&lt;/li&gt;
&lt;li&gt;Each &lt;strong&gt;tab&lt;/strong&gt; MUST include &lt;code&gt;aria-selected&lt;/code&gt; (true or false), &lt;code&gt;tabindex&lt;/code&gt;, and &lt;code&gt;aria-controls&lt;/code&gt; attributes:
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;aria-selected&lt;/code&gt;: to indicate the current state of the tab (whether it's active or not).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;tabindex&lt;/code&gt;: The active tab should have tabindex="0" and inactive tabs should have tabindex="-1", to prevent them from being focusable until activated.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;aria-controls&lt;/code&gt;: should point to the id of the respective tabpanel, this will link the tab to its associated tabpanel.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt; Each &lt;strong&gt;tabpanel&lt;/strong&gt; MUST have &lt;code&gt;tabindex="0"&lt;/code&gt; to ensure it's focusable when activated, and &lt;code&gt;aria-labelledby&lt;/code&gt;. The &lt;code&gt;aria-labelledby&lt;/code&gt; attribute should link to the &lt;code&gt;id&lt;/code&gt; of the respective tab, to indicate which tab controls the panel. &lt;/li&gt;

&lt;/ul&gt;
&lt;h3&gt;
  
  
  Tab Behaviors
&lt;/h3&gt;

&lt;p&gt;APG provides two examples of the tab behavior:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Tabs With Automatic Activation: The tabs are automatically activated as they receive focus, and the respective panel is displayed. This behavior should ideally be the default. However, this behaviour is only recommended when switching tabs does not cause content loading delays or layout shifts. If delays are present, manual activation should be used to avoid a frustrating user experience.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Tabs With Manual Activation: The tabs are activated by pressing the &lt;code&gt;Space&lt;/code&gt; or &lt;code&gt;Enter&lt;/code&gt; key. This behavior works well in scenarios where the user might need to carefully choose or confirm the content they wish to view, such as in a form with dynamic content that could change based on the user's choice.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Accessibility Features
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Tab Indexing: The active tab has a tabindex="0", while the other tabs have tabindex="-1". This ensures that keyboard and screen reader users can move between content efficiently without having to go through all of the tabs.&lt;/li&gt;
&lt;li&gt;Tabpanel Focus: The tabpanel has a tabindex="0" to make it easy for screen reader users to move from a tab to the beginning of the tabpanel content.&lt;/li&gt;
&lt;li&gt;Keyboard Navigation: Keyboard users can navigate between tabs using the left and right arrow keys. The tab navigation is looped, so if the user is at the beginning of the tab list and presses the left arrow key, focus will move to the last tab.&lt;/li&gt;
&lt;li&gt;Visible Focus State: The active tab has a visible style that doesn't rely on color alone, so users with low vision, color blindness, or high contrast settings can easily distinguish the active tab from the others.&lt;/li&gt;
&lt;li&gt;Responsive Design: Relative units are used to specify the component's width (if provided), ensuring that the tab content remains accessible and visible when the screen is magnified.&lt;/li&gt;
&lt;li&gt;Clear Labeling: The aria-labelledby attribute is used to associate the tabpanel with the corresponding tab, making it clear for screen reader users which content corresponds to which tab.&lt;/li&gt;
&lt;li&gt;Focus Management: When a tab is activated (either through keyboard or mouse interaction), the focus should move to the tabpanel or the first interactive element inside the tabpanel, this ensures a smooth navigation for screen reader and keyboard users.&lt;/li&gt;
&lt;li&gt;Consistent Order: Ensure that the tab focus follows a logical, visual order. For example, a keyboard user should not move from tab 1 to tab 6 and then to tab 3 if that isn't the visible order of the tabs. The tablist should follow the visual sequence, and each tabpanel should correspond to the active tab in that same order, to ensure a predictable navigation.&lt;/li&gt;
&lt;li&gt;Auto-activation of Tabs: APG recommends that tabs should automatically activate when they receive focus, except when switching tabs could cause content delay, layout shifts, or page reloads. This allows for a simpler navigation experience for keyboard users.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Keyboard Interaction
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Tab:

&lt;ul&gt;
&lt;li&gt;Moves focus to the active tab element&lt;/li&gt;
&lt;li&gt;If a tab is focused, the focus moves to the next focusable element which should be the tabpanel, or the first focusable element in the tabpanel&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;In the tab list

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Left Arrow&lt;/code&gt;: Moves focus to the previous tab. If the first tab is focused, focus moves to the last tab in the list (looping behavior)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Right Arrow&lt;/code&gt;: Moves focus to the next tab. If the last tab is focused, focus moves to the first tab&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Home&lt;/code&gt;: Moves focus to the first tab in the tab list.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;End&lt;/code&gt;: Moves focus to the last tab in the tab list.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Space&lt;/code&gt; or &lt;code&gt;Enter&lt;/code&gt;: Activates the focused tab if it wasn't activated automatically on focus&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Delete&lt;/code&gt;(Optionally): If deletion is allowed, deletes the current tab and its associated tabpanel. After deletion, the next or previous tab is activated, depending on availability&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Implementation
&lt;/h3&gt;

&lt;p&gt;In this implementation, I used Tailwind CSS for styling the elements, and I've ensured that the layout is flexible and responsive. The primary focus here is on the accessibility and functionality of the tab interaction, which I've implemented using TypeScript.&lt;/p&gt;
&lt;h4&gt;
  
  
  The &lt;code&gt;activateTab&lt;/code&gt; Function
&lt;/h4&gt;

&lt;p&gt;In the code, both the tab components use the activateTab function. The function takes three params (tabs, panels, index); however, you don't need that for your implementation. Ideally, you'll only need the index parameter.&lt;/p&gt;

&lt;p&gt;The function does the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sets the aria-selected attribute: This tells screen readers and other assistive technologies which tab is selected. The active tab gets aria-selected="true", and inactive tabs get aria-selected="false".&lt;/li&gt;
&lt;li&gt;Manages tabindex for Focus: The active tab has a tabindex="0", which means it is focusable and navigable via keyboard. The inactive tabs get a tabindex="-1", which makes them non-focusable until they're activated.&lt;/li&gt;
&lt;li&gt;Visibility of Content: Each tab has a .active class that is toggled to add an active style to the active tab. Each tabpanel has a corresponding .active-panel class that is toggled to show or hide the content based on the active tab. Only the tabpanel that corresponds to the selected tab is visible.&lt;/li&gt;
&lt;li&gt;Focus Handling: Finally, after making the tab active, tabs[index].focus() ensures that focus is moved to the selected tab, so the user can immediately interact with it, whether via keyboard or screen reader.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/leezee/embed/jEbwyWv?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Feel free to explore the working examples on CodePen and experiment with both versions of the tab component.&lt;/p&gt;




&lt;p&gt;If you found this tutorial helpful, connect with me on &lt;a href="https://www.linkedin.com/in/elizabeth-meshioye/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; and &lt;a href="https://bsky.app/profile/ilizette.bsky.social" rel="noopener noreferrer"&gt;Bluesky&lt;/a&gt; for more accessibility tips and updates!&lt;/p&gt;

</description>
      <category>a11y</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>frontend</category>
    </item>
    <item>
      <title>What is Motion Sensitivity? How to Design Accessible Web Animations</title>
      <dc:creator>Elizabeth</dc:creator>
      <pubDate>Thu, 08 Feb 2024 09:16:30 +0000</pubDate>
      <link>https://dev.to/ilizette/what-is-motion-sensitivity-how-to-design-accessible-web-animations-5dej</link>
      <guid>https://dev.to/ilizette/what-is-motion-sensitivity-how-to-design-accessible-web-animations-5dej</guid>
      <description>&lt;p&gt;As web developers, we love a good animation, right? But let's be honest, sometimes we get caught up in the wow factor and forget that our websites exist for real people with diverse needs.&lt;/p&gt;

&lt;p&gt;One hidden hurdle for some users is motion sensitivity. It might not be something we think about every day, but it can have a big impact on how people experience the internet.&lt;/p&gt;

&lt;p&gt;In this article, I want to shine a light on motion sensitivity. We'll explore what it's like, the conditions it's linked to, and how it can affect someone's ability to enjoy using a website.&lt;/p&gt;

&lt;p&gt;My goals for this article are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To get you thinking about creating web experiences that are comfortable and welcoming for everyone.&lt;/li&gt;
&lt;li&gt;To equip you with practical tips to make that happen. Because an inclusive web is a better web for everyone.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What is Motion Sensitivity?
&lt;/h2&gt;

&lt;p&gt;Motion sensitivity isn't just a technical term – it refers to how we experience the digital world, especially for those whose sensitivities go beyond what meets the eye. So, let's unravel this concept and see why it matters.&lt;/p&gt;

&lt;p&gt;According to &lt;a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC7418000/#:~:text=Motion%20sensitivity%20is%20characterized%20by,dizziness%20%5B1%2D3%5D"&gt;National Library of Medicine&lt;/a&gt; motion sensitivity refers to a condition where a person experiences symptoms such as dizziness, nausea, and imbalance in response to motion. This can be caused by a variety of factors, including inner ear problems, neurological disorders, and certain medications.&lt;/p&gt;

&lt;p&gt;People with motion sensitivity may have difficulty tolerating activities that involve moving, such as riding in cars and even certain motion animations.&lt;/p&gt;

&lt;p&gt;Maybe you've taken a long road trip and experienced motion sickness. Or you've visited the cinema to see a 3D movie and, instead of enjoying the experience, you end up with headaches, migraine, dizziness, or nausea. Then you understand how serious motion sensitivity can be.&lt;/p&gt;

&lt;h3&gt;
  
  
  How Motion Sensitivity Impacts People
&lt;/h3&gt;

&lt;p&gt;For some people, motion effects like parallax scrolling can be annoying, but the effects of motion sensitivity go beyond a mere inconvenience. It can disrupt the digital experience and, more importantly, affect the well-being of those navigating the space.&lt;/p&gt;

&lt;p&gt;Some people might feel dizzy, nauseous, or experience headaches or migraines when faced with certain animations or transitions. For them, accessing digital content becomes more than just a click – it's a consideration of their comfort and health.&lt;/p&gt;

&lt;h3&gt;
  
  
  Insights into Related Disorders
&lt;/h3&gt;

&lt;p&gt;To truly understand motion sensitivity, I believe we need to explore the conditions linked to it, mainly vestibular disorders and visual motion sensitivity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vestibular Disorders&lt;/strong&gt; impact the inner ear and how the brain processes spatial information. For someone with vestibular disorders, simple tasks like maintaining balance or handling motion stimuli can become challenging.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Visual Motion Sensitivity&lt;/strong&gt; is about heightened sensitivity to visual stimuli, leading to discomfort or adverse reactions to certain types of motion. For someone with visual motion sensitivity, navigating websites with specific animations or scrolling behaviors can be a struggle.&lt;/p&gt;

&lt;p&gt;By diving into these facets of motion sensitivity, we lay the groundwork for creating digital spaces that acknowledge and respect diverse user experiences.&lt;/p&gt;

&lt;h3&gt;
  
  
  So, Why Does this Matter?
&lt;/h3&gt;

&lt;p&gt;Well, I think it is as simple as this: everyone deserves to enjoy the digital world without feeling unwell. Understanding motion sensitivity helps us create websites, games, and apps that are more inclusive and comfortable for everyone, not just folks with superhero vision.&lt;/p&gt;

&lt;p&gt;Let's explore why designing with motion sensitivity in mind is not just a best practice but a step towards a more inclusive online world.&lt;/p&gt;

&lt;h3&gt;
  
  
  How Common is Motion Sensitivity?
&lt;/h3&gt;

&lt;p&gt;Motion sensitivity is more common than you might think. According to &lt;a href="https://archivesphysiotherapy.biomedcentral.com/articles/10.1186/s40945-020-00077-9#:~:text=It%20has%20been%20reported%20that,men%20%5B2%2C%203%5D."&gt;this article&lt;/a&gt; from Archives of Physiotherapy, it has been reported that 28.4% of the population experience motion sensitivity. Also, according to &lt;a href="https://en.wikipedia.org/wiki/Motion_sickness#:~:text=of%20motion%20sickness.-,Epidemiology,medium%20to%20high%20motion%20sickness"&gt;this article&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Nearly all people are affected with sufficient motion and most people will experience motion sickness at least once in their lifetime. Susceptibility, however, is variable, with about one-third of the population being highly susceptible while most other people are affected under extreme conditions. Women are more easily affected than men.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;These statistics underscore the need for web designers and developers to consider motion sensitivity in our creations. They highlight that what might be a visually engaging animation for one user could be an obstacle for another.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Identify Motion-Sensitive Triggers in Animations
&lt;/h2&gt;

&lt;p&gt;Animation can enhance engagement and help guide users through the app. But it is vital that we scrutinize the types of animations we incorporate into our designs, particularly when aiming for motion-friendly experiences.&lt;/p&gt;

&lt;p&gt;Let's explore these potential triggers and discuss alternatives to ensure a more inclusive design.&lt;/p&gt;

&lt;h3&gt;
  
  
  Rapid or Flickering Animations
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Trigger Potential:&lt;/strong&gt;  Quick, flickering animations can be disorienting for users with motion sensitivity, leading to discomfort or headaches. Examples of these types of animations include rapidly blinking notifications, flickering banners, or flashing call-to-action buttons.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Alternative Approach:&lt;/strong&gt; Opt for smoother transitions like subtle fades or slides, avoiding rapid flickering effects for a more comfortable experience.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Overly Complex Transitions
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Trigger Potential:&lt;/strong&gt; Elaborate loading animations with intricate patterns, complex slide-in effects, or overly detailed transitions between pages may overwhelm users, causing sensory overload for those with motion sensitivity.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Alternative Approach:&lt;/strong&gt; Simplify transitions, focus on clarity and purpose. Strive for elegance in design without unnecessary visual complexity.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Bouncing or Elastic Motions
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Trigger Potential:&lt;/strong&gt; Animations with bouncing or elastic movements can induce dizziness or nausea in motion-sensitive users. Examples include buttons that bounce upon interaction or elastic-scrolling effects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Alternative Approach:&lt;/strong&gt; Choose more subtle easing functions for animations, providing a smoother and less physically demanding experience.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  High-Speed Animations
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Trigger Potential:&lt;/strong&gt; High-speed carousels, rapid image sliders, or quick-scrolling features may challenge users with motion sensitivity, potentially leading to feelings of discomfort or disorientation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Alternative Approach:&lt;/strong&gt; Allow users to control animation speeds or default to slower, more deliberate transitions for a universally comfortable pace.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Continuous Auto-Scrolling
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Trigger Potential:&lt;/strong&gt; Auto-scrolling features that move content continuously without user interaction, like automatic slideshows or news tickers, can be unsettling for users with motion sensitivity.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Alternative Approach:&lt;/strong&gt; Implement user-initiated scrolling, providing control to the user and avoiding unexpected motion.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Flashing or Intense Color Changes
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Trigger Potential:&lt;br&gt;
Flashing animations or sudden, intense color changes can be visually overwhelming and trigger discomfort. Examples include flashing banners, intense color changes on hover, or rapidly changing background colors.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Alternative Approach:&lt;/strong&gt; Maintain a consistent color palette and avoid rapid, drastic color shifts. Consider softer transitions for color changes.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Rotational Movements
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Trigger Potential:&lt;/strong&gt; Rotational animations, such as spinning logos or rotating carousels, may cause dizziness or vertigo for individuals with vestibular disorders or motion sensitivity.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Alternative Approach:&lt;/strong&gt; Minimize or eliminate rotational motions, especially in situations where they may not be essential for understanding the content.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By recognizing these potential triggers and adopting alternative approaches, we can create digital experiences that are more considerate and welcoming for users with motion sensitivity.&lt;/p&gt;

&lt;p&gt;The goal is not to stop adding animations but to design with empathy, ensuring that motion enhances rather than detracts from the user experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Use Reduce-Motion Preferences
&lt;/h2&gt;

&lt;p&gt;One significant stride towards motion-friendly web design is utilizing the &lt;code&gt;reduce-motion&lt;/code&gt; preferences embedded in operating systems and browsers. This preference provide users with the option to minimize or eliminate unnecessary animations.&lt;/p&gt;

&lt;p&gt;By recognizing and respecting these user preferences, we can significantly enhance the accessibility of web applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  Incorporate Reduced Motion Features
&lt;/h3&gt;

&lt;p&gt;For developers, integrating reduced motion features into web applications involves a combination of coding practices and user interface considerations.&lt;/p&gt;

&lt;p&gt;Begin by identifying areas where animations can be toned down or replaced with static alternatives. Implementing conditional checks for reduce-motion preferences in your codebase allows your web application to adapt dynamically, providing a smoother experience for users who opt for reduced motion.&lt;/p&gt;

&lt;h4&gt;
  
  
  CSS prefers-reduced-motion Media Feature
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.animated-element&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;animation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;pulse&lt;/span&gt; &lt;span class="m"&gt;1s&lt;/span&gt; &lt;span class="n"&gt;linear&lt;/span&gt; &lt;span class="n"&gt;infinite&lt;/span&gt; &lt;span class="nb"&gt;both&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* Tone down the animation */&lt;/span&gt;
&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prefers-reduced-motion&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nc"&gt;.animated-element&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;animation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;smooth&lt;/span&gt; &lt;span class="m"&gt;4s&lt;/span&gt; &lt;span class="n"&gt;linear&lt;/span&gt; &lt;span class="n"&gt;infinite&lt;/span&gt; &lt;span class="nb"&gt;both&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  JavaScript Reduced Motion Detection
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Check if the user prefers reduced motion using JavaScript&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;prefersReducedMotion&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;matchMedia&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;(prefers-reduced-motion: reduce)&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;matches&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Example of adjusting animation based on reduced motion preference&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;animatedElement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.animated-element&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prefersReducedMotion&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;animatedElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;animation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;smooth 4s linear infinite both&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;animatedElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;animation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pulse 1s linear infinite both&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Test Your Animation on Chrome
&lt;/h4&gt;

&lt;p&gt;While basic accessibility checks are readily available, Chrome DevTools offers advanced capabilities through its hidden &lt;strong&gt;Rendering tool&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;One of the options available in the rendering tool is the option to test your animation for when a user enables &lt;code&gt;prefers-reduced-motion&lt;/code&gt;. Here's how to leverage it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click the customize (three dots) icon in the DevTools panel&lt;/li&gt;
&lt;li&gt;Select more tools&lt;/li&gt;
&lt;li&gt;Select &lt;strong&gt;Rendering&lt;/strong&gt; option from the list of options&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flb9z524kbj315mlzkrw7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flb9z524kbj315mlzkrw7.png" alt="The chrome dev tool" width="800" height="726"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Once enabled, the &lt;strong&gt;Rendering&lt;/strong&gt; tab appears in DevTools.&lt;/li&gt;
&lt;li&gt;Look for the option named  &lt;strong&gt;"Emulate CSS media feature prefers-reduced-motion."&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Enable this option to preview how your website's animations appear for users who have set their device or browser to reduce motion.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd3c3r0129ucwrx4mdjoo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd3c3r0129ucwrx4mdjoo.png" alt="Chrome rendering tool for reduced-motion" width="800" height="246"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When a user has &lt;code&gt;prefers-reduced-motion&lt;/code&gt; enabled, avoid completely removing animations. Aim to provide users with a smoother experience rather than completely excluding them from the interactive experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  Motion Sensitivity Tips and Best Practices
&lt;/h2&gt;

&lt;p&gt;Let's explore tips and best practices to incorporate into our designs:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Subtle Animations: Opt for subtle animations that convey information without being overwhelming. Gentle fades, transitions, and loading effects can enhance the user experience without causing discomfort.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Adjustable Speeds: Provide users with the ability to control animation speeds. Implement settings within your application that allow users to customize the speed of transitions, ensuring a comfortable experience for everyone.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Clear Navigation Signals: Use motion to guide users intuitively. For instance, employ subtle animations to indicate a change in state or to draw attention to important elements, ensuring that users with motion sensitivity can follow the flow without feeling disoriented.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;User Testing: Conduct thorough user testing, specifically with individuals who experience motion sensitivity. Gather feedback to refine your design, ensuring that it meets the needs of the diverse user base.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Document and Communicate: Clearly document your approach to motion-friendly design in your project documentation. This not only serves as a reference for your team but also communicates your commitment to accessibility to stakeholders and users.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Motion sensitivity isn't a rare exception – it's a shared experience for many people. Our responsibility as web developers is not merely to acknowledge this reality but to actively integrate inclusivity into the DNA of our creations.&lt;/p&gt;

&lt;p&gt;By identifying potential triggers and implementing reduced motion features using technologies like &lt;code&gt;prefers-reduced-motion&lt;/code&gt; in CSS and JavaScript, we create spaces that accommodate diverse needs without compromising on engagement.&lt;/p&gt;

&lt;p&gt;Accessibility is not a trend, it's a fundamental ethos that shapes the future of the internet into one where everyone regardless of their abilities can use the internet with comfort.&lt;/p&gt;

&lt;p&gt;Thank you so much for reading this article, if you found it helpful consider sharing. Happy coding!&lt;/p&gt;




&lt;p&gt;You can connect with me on &lt;a href="https://www.linkedin.com/in/elizabeth-meshioye/"&gt;Linkedin&lt;/a&gt; or &lt;a href="https://github.com/Lezette"&gt;Github&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Val Head. Designing Safer Web Animation For Motion Sensitivity (September 08, 2015) &lt;a href="https://alistapart.com/article/designing-safer-web-animation-for-motion-sensitivity/"&gt;https://alistapart.com/article/designing-safer-web-animation-for-motion-sensitivity/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Chaudhary, S., Saywell, N., Kumar, A., &amp;amp; Taylor, D. (2020). Visual Fixations and Motion Sensitivity: Protocol for an Exploratory Study. JMIR Research Protocols, 9(7). &lt;a href="https://doi.org/10.2196/16805"&gt;https://doi.org/10.2196/16805&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Albalwi, A.A., Johnson, E.G., Alharbi, A.A. et al. Effects of head motion on postural stability in healthy young adults with chronic motion sensitivity. Arch Physiother10, 6 (2020). &lt;a href="https://doi.org/10.1186/s40945-020-00077-9"&gt;https://doi.org/10.1186/s40945-020-00077-9&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Motion sickness. (2024, January 1). In Wikipedia. &lt;a href="https://en.wikipedia.org/wiki/Motion_sickness"&gt;https://en.wikipedia.org/wiki/Motion_sickness&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>a11y</category>
      <category>frontend</category>
      <category>learning</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to build an accessible navigation menu</title>
      <dc:creator>Elizabeth</dc:creator>
      <pubDate>Wed, 06 Dec 2023 12:02:17 +0000</pubDate>
      <link>https://dev.to/ilizette/how-to-build-an-accessible-navigation-menu-1omk</link>
      <guid>https://dev.to/ilizette/how-to-build-an-accessible-navigation-menu-1omk</guid>
      <description>&lt;p&gt;Hey there! Today, we're looking into how to build an accessible menu. I decided to write this article because recently, while running an accessibility test on some websites, including some of my past projects, one common issue was that navigating submenus with just a keyboard or screen reader was trickier than it should be.&lt;/p&gt;

&lt;p&gt;This article aims to show you what to do when building a navigation and fix any oopsies you might have made. I have also added an example of a simple menu. Ready to dive in? 😅&lt;/p&gt;

&lt;h2&gt;
  
  
  Semantic HTML and aria
&lt;/h2&gt;

&lt;p&gt;Optimizing your code for readability is as simple as choosing the right HTML tags. Consider this transformation:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;nav&amp;gt;
 &amp;lt;ul&amp;gt;
   &amp;lt;li&amp;gt;&amp;lt;a href="#"&amp;gt;list item 1&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
   &amp;lt;li&amp;gt;&amp;lt;a href="#"&amp;gt;list item 2&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
   &amp;lt;li&amp;gt;&amp;lt;a href="#"&amp;gt;list item 3&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
 &amp;lt;/ul&amp;gt;
&amp;lt;/nav&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;which is far more legible compared to:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;div&amp;gt;
  &amp;lt;div&amp;gt;
    &amp;lt;a href="#"&amp;gt;list item 1&amp;lt;/a&amp;gt;
    &amp;lt;a href="#"&amp;gt;list item 2&amp;lt;/a&amp;gt;
    &amp;lt;a href="#"&amp;gt;list item 3&amp;lt;/a&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Not only is the first example more readable, but it also ensures that a screen reader lets the user know that they're currently on the navigation.&lt;/p&gt;

&lt;p&gt;However, sometimes using the right semantic element might not explain the role of our element properly, This is where using aria and roles shine. In the first example, we have a &lt;code&gt;&amp;lt;ul&amp;gt;&lt;/code&gt; which is currently a list, we don't want the browser to see it as a list, the ul is supposed to act as a menubar so we can improve the code by adding a &lt;code&gt;role="menubar"&lt;/code&gt;, a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/menubar_role#description" rel="noopener noreferrer"&gt;menubar can have a&lt;/a&gt; &lt;code&gt;menuitem&lt;/code&gt;, &lt;code&gt;menuradio&lt;/code&gt;, or &lt;code&gt;menuitemcheckbox&lt;/code&gt;. In our case, we only need a menuitem.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;nav&amp;gt;
 &amp;lt;ul role="menubar"&amp;gt;
   &amp;lt;li role="none"&amp;gt;&amp;lt;a href="#" role="menuitem"&amp;gt;list item 1&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
   &amp;lt;li role="none"&amp;gt;&amp;lt;a href="#" role="menuitem"&amp;gt;list item 2&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
   &amp;lt;li role="none"&amp;gt;&amp;lt;a href="#" role="menuitem"&amp;gt;list item 3&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
 &amp;lt;/ul&amp;gt;
&amp;lt;/nav&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;In the updated code I added a &lt;code&gt;role="none"&lt;/code&gt; to the &lt;code&gt;li&lt;/code&gt; tag, this is because the &lt;code&gt;li&lt;/code&gt; will be acting as a container for this example, the &lt;a&gt; element is explicitly designated as a &lt;code&gt;menuitem&lt;/code&gt;.&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Please note that there's such a thing as using the wrong aria, if you don't use aria correctly it could break your accessibility. A rule of thumb is "No aria is better than bad aria". You can read more about this &lt;a href="https://www.w3.org/WAI/ARIA/apg/practices/read-me-first/" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Code structure for focus order
&lt;/h2&gt;

&lt;p&gt;While you can always move things with CSS when building an accessible platform you need to ensure your elements are structured as they appear. A Properly structured code helps in managing the focus order. When users press the &lt;code&gt;Tab&lt;/code&gt; key to move through interactive elements, the focus should follow a logical order. Without proper structure, the focus might jump unpredictably, making navigation difficult. &lt;/p&gt;

&lt;p&gt;This is also important when working with a submenu, for example: if a user has to tab through all the menuitems before they can get to a submenu then the navigation isn't friendly. Instead of having a code like this:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;nav&amp;gt;
 &amp;lt;ul role="menubar" id="mainmenu"&amp;gt;
   &amp;lt;li role="none"&amp;gt;&amp;lt;a href="#" role="menuitem"&amp;gt;list item 1&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
   &amp;lt;li role="none"&amp;gt;&amp;lt;a href="#" role="menuitem"&amp;gt;list item 2&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
   &amp;lt;li role="none"&amp;gt;&amp;lt;a href="#" role="menuitem"&amp;gt;list item 3&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
 &amp;lt;/ul&amp;gt;
&amp;lt;ul id="submenuList1"&amp;gt;
  &amp;lt;li role="none"&amp;gt;&amp;lt;a href="#" role="menuitem"&amp;gt;sub list item 1&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
&amp;lt;li role="none"&amp;gt;&amp;lt;a href="#" role="menuitem"&amp;gt;sub list item 2&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
&amp;lt;/ul&amp;gt;
&amp;lt;/nav&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;We can do this:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;nav&amp;gt;
 &amp;lt;ul role="menubar"&amp;gt;
   &amp;lt;li role="menuitem"&amp;gt;List item 1
   &amp;lt;ul role="menu"&amp;gt;
     &amp;lt;li role="none"&amp;gt;&amp;lt;a href="#" role="menuitem"&amp;gt;sub list item 1&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
     &amp;lt;li role="none"&amp;gt;&amp;lt;a href="#" role="menuitem"&amp;gt;sub list item 2&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
   &amp;lt;/ul&amp;gt;
  &amp;lt;/li&amp;gt;
   &amp;lt;li role="none"&amp;gt;&amp;lt;a href="#" role="menuitem"&amp;gt;list item 2&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
   &amp;lt;li role="none"&amp;gt;&amp;lt;a href="#" role="menuitem"&amp;gt;list item 3&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
 &amp;lt;/ul&amp;gt;
&amp;lt;/nav&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Remember, you can always move things with CSS, but if your HTML is not structured, the experience will be different for keyboard users and screen readers. Here's an example of me using a screen reader to access a menu with a submenu.&lt;/p&gt;


&lt;div&gt;
  &lt;iframe src="https://loom.com/embed/8f280344f94c4db588dd1111952c72ee"&gt;
  &lt;/iframe&gt;
&lt;/div&gt;



&lt;p&gt;Here's the link to the &lt;a href="https://codepen.io/leezee/pen/YzBaRwg" rel="noopener noreferrer"&gt;codepen&lt;/a&gt; you can test it on a keyboard and screen reader.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In a future article, I'll be sharing how to test with screen readers &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Conlusion
&lt;/h2&gt;

&lt;p&gt;Almost every web platform has a menu, it's what gives users an idea of what to expect. If some users cannot access it then your platform is not complete. You need to ensure that the experience is easy for everyone by ensuring that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A user can navigate the menubar without using a mouse&lt;/li&gt;
&lt;li&gt;A user can open and close the submenu without the mouse. for example: when a user clicks on the enter/return or the space key it should toggle the submenu.&lt;/li&gt;
&lt;li&gt;A screen reader can read to the user that they're on a menuitem or a submenu.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want to know how to run a full test for accessibility, I wrote an article on it. You can find it ↓&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/ilizette" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F187170%2Fefb92216-7bac-4c77-96f7-d687875f6053.png" alt="ilizette"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/ilizette/how-i-test-a-website-for-accessibility-167g" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;How I test a website for accessibility&lt;/h2&gt;
      &lt;h3&gt;Elizabeth ・ Nov 14 '23&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#a11y&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#frontend&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;It is our duty to make the internet experience awesome for everyone. &lt;/p&gt;




&lt;p&gt;Thank you for reading this article. If you liked it, feel free to give it a thumbs up and share it. Drop your thoughts in the comments—I'm curious about what you think. Got a specific accessibility topic in mind? Tell me in the comments, and I'll try my hand at it. Until next time, have an awesome week or weekend! 😁&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/B4AgWgg9DIBsAwv0kL/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/B4AgWgg9DIBsAwv0kL/giphy.gif"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>frontend</category>
      <category>a11y</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How I test a website for accessibility</title>
      <dc:creator>Elizabeth</dc:creator>
      <pubDate>Tue, 14 Nov 2023 10:00:00 +0000</pubDate>
      <link>https://dev.to/ilizette/how-i-test-a-website-for-accessibility-167g</link>
      <guid>https://dev.to/ilizette/how-i-test-a-website-for-accessibility-167g</guid>
      <description>&lt;p&gt;In today's lesson, I'll guide you through my approach to accessibility testing. We'll explore utilizing Google Lighthouse for automated a11y testing, delve into manual testing with keyboards, and learn how to emulate various media states, and visual impairment using the Chrome browser.&lt;/p&gt;

&lt;p&gt;For this article, we'll be testing this &lt;a href="https://codepen.io/leezee/pen/eYbXzpJ" rel="noopener noreferrer"&gt;demo webpage on CodePen&lt;/a&gt; or you can clone this &lt;a href="https://github.com/Lezette/wandawave-accessibility-test" rel="noopener noreferrer"&gt;Github repo&lt;/a&gt;. I intentionally made the webpage inaccessible and included common errors. We will fix these issues together.&lt;/p&gt;

&lt;h2&gt;
  
  
  Automated Testing using Lighthouse
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://developer.chrome.com/docs/lighthouse/overview/" rel="noopener noreferrer"&gt;Lighthouse&lt;/a&gt; is an open-source tool that was created to help improve the quality of a website. We'll be using it to test for accessibility, It gives quick results in just a few steps. We'll be using Chrome to test since the lighthouse is built-in&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Fork and activate debug mode on the pen
&lt;/h3&gt;

&lt;p&gt;This action will generate a temporary URL for testing purposes. Debugging in the CodePen's debug view simplifies the process, eliminating the need to inspect through an iframe.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffpjkaoy31fhwl3abnxdq.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffpjkaoy31fhwl3abnxdq.jpeg" alt="find debug mode on codepen"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Open Lighthouse on Chrome devtool
&lt;/h3&gt;

&lt;p&gt;Pop open your browser's DevTools and head over to the Lighthouse tab. Since we're focusing solely on accessibility testing, uncheck all the other category options except Accessibility.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa2j9oq2t8w5lsr6tz15n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa2j9oq2t8w5lsr6tz15n.png" alt="lighthouse interface"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click the "Analyze page load" button, and let Lighthouse run its test.&lt;/p&gt;

&lt;p&gt;After the wait, Lighthouse will show the calculated score and a detailed list of issues that were found. In this case, we got 68% (orange) on accessibility.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq1kgnvs0pcst9xuz73qq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq1kgnvs0pcst9xuz73qq.png" alt="Lighthouse test score 68% on accessibility and list of issues found"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Now, if this were my math test, I might call it a win, but in the world of accessibility, we've got to do better than this, right? 👀&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;So let's uncover the issues and fix them one at a time.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Issue 1: NAMES AND LABELS
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Image elements do not have [alt] attributes&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To fix that we just add the alt attribute to the images. Image alt text should be short if they're supposed to be informative or left empty if they're purely for decoration.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;img alt="a brown building" src="https://source.unsplash.com/kn_ANxnwCQ0/400x300" class="lg:w-10/12 lg:object-cover inline-block mx-auto" /&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Links do not have a discernible name&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When incorporating links, it's crucial to provide users with clear information about the destination. If the link is an image, it can be fixed using an alt text. In our demo page, we have several SVG images wrapped in a link. To fix this, we'll add &lt;code&gt;role="img"&lt;/code&gt; attributes to the SVG tag and include a &lt;code&gt;&amp;lt;title&amp;gt;&lt;/code&gt; tag within the SVG.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;svg role="img" width="25px" height="25px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"&amp;gt;
    &amp;lt;title&amp;gt;Contact me via email&amp;lt;/title&amp;gt;
....


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Issue 2: ARIA
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;button, link, and menuitem elements do not have accessible names.&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Lighthouse conveniently highlights the specific code where it detects an issue, making it easy to pinpoint. In this particular section, the problem stems from the following code and other parts where it's repeated. &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

 &amp;lt;i role="button" tabindex="1" class="fa-solid fa-chevron-right fa-rotate-180" style="color: #9da3af;"&amp;gt;&amp;lt;/i&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In this instance, a &lt;code&gt;role="button"&lt;/code&gt; is present, but the absence of a title leaves no descriptive information for screen readers to convey. To fix this issue, we can add a &lt;code&gt;title&lt;/code&gt; attribute or an &lt;code&gt;aria-label&lt;/code&gt;. In this case, we'll opt for the use of aria-label.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;i role="button" aria-label="Previous" class="fa-solid fa-chevron-right fa-rotate-180" style="color: #9da3af;"&amp;gt;&amp;lt;/i&amp;gt;

&amp;lt;i role="button" aria-label="Next" class="fa-solid fa-chevron-right" style="color: #323439;"&amp;gt;&amp;lt;/i&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Issue 3: CONTRAST
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Background and foreground colors do not have a sufficient contrast ratio.&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Web Content Accessibility Guidelines (WCAG) set rules to make sure the contrast between a background and a foreground color is good enough for everyone to read, especially for those with vision challenges. So, as a developer, it's about picking colors that play nicely together, making your content accessible to as many people as possible.&lt;/p&gt;

&lt;p&gt;In our demo, we're using a light turquoise color on a white background. &lt;/p&gt;

&lt;p&gt;To rectify this, We have two options: increasing the font size and making it bold, or changing the color. For this demo, we'll opt for a color change. Lucky for us, chrome DevTools can help us identify an appropriate color with the right contrast. &lt;/p&gt;

&lt;p&gt;Let's correct the contrast:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Navigate to the Element tab in the devtool and select one of the turquoise texts on the white background. Under the styles section find the &lt;code&gt;text-color&lt;/code&gt; and click on the turquoise square to show a color wheel popup. The popup also shows the contrast ratio which is currently &lt;code&gt;1.96&lt;/code&gt;. Click on the dropdown and the color wheel will now have two lines.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Head to the Element tab in the DevTools and choose one of the turquoise texts on the white background. In the Styles section, locate the &lt;code&gt;text-color&lt;/code&gt; property, and click on the turquoise square to reveal a color wheel popup. This popup displays the current contrast ratio, currently at 1.96. Click on the dropdown, and the color wheel will now show two lines. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F85r75sa3kue9owltu2n0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F85r75sa3kue9owltu2n0.png" alt="chrome color wheel with contrast information"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The colors under these lines will meet the criteria for a sufficient contrast.&lt;br&gt;
...&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In the CSS let's update the color&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

:root {
  --main-color: #016d73;
  --secondary-color: #94bbe9;
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Issue 4: NAVIGATION
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Some elements have a [tabindex] value greater than 0&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F890s1usqvgufmnrbwb3y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F890s1usqvgufmnrbwb3y.png" alt="failing tabindex code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Please note that you might not see this issue if you selected the desktop option before running the analysis on lighthouse; This only shows on mobile&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Using a tabindex value of 0 for both elements is just fine and will work exactly as expected. Using a value greater than 0 will jump ahead of everything else in the tab order and these often create poor experiences for users who rely on assistive technologies. Now there are instances where using a value greater than 0 could be valid but not in this case. &lt;/p&gt;

&lt;p&gt;Let's fix this:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;i role="button" tabindex="0" class="fa-solid fa-chevron-right fa-rotate-180" style="color: #9da3af;"&amp;gt;&amp;lt;/i&amp;gt;
&amp;lt;i role="button" tabindex="0"  class="fa-solid fa-chevron-right"&amp;gt;&amp;lt;/i&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;p&gt;After addressing all of the issues from lighthouse rerun the test. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6gttkcxoqnb5uenpr8n7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6gttkcxoqnb5uenpr8n7.png" alt="Updated lighthouse score"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This time we should get 100 (green) on lighthouse. Here's the &lt;a href="https://codepen.io/leezee/pen/zYygGbm" rel="noopener noreferrer"&gt;updated pen after fixing the automated testing issues&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, that's not the end of testing for a11y. Automated testing is just a part of the process. Lighthouse doesn't test for all instances a11y. So the next process is to do a manual test.&lt;/p&gt;




&lt;h2&gt;
  
  
  Manual testing
&lt;/h2&gt;

&lt;p&gt;When testing for a11y manually there are several factors to test for, e.g.: trying to navigate the website only using a keyboard, using a screen reader, trying to emulate different media types, and visual impairments. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Running a manual test on our updated demo:&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Semantic tags
&lt;/h3&gt;

&lt;p&gt;A glance at the code will reveal that we used divs for page structure. The code doesn't look so structured and it's the same for users accessing the website through a screen reader. Let's fix that:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy18md02q4k0qy14gbyxy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy18md02q4k0qy14gbyxy.png" alt="updated semantic code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the picture above, I have replaced the page structure with their semantic elements, using the &lt;code&gt;header&lt;/code&gt;, &lt;code&gt;main&lt;/code&gt;, &lt;code&gt;footer&lt;/code&gt;, and &lt;code&gt;section&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Keyboard navigation test
&lt;/h3&gt;

&lt;p&gt;Now let's try navigating the website using the keyboard. Using the &lt;code&gt;tab&lt;/code&gt; key. You'll notice that there's no way to know exactly where we are on the website. This is because there's no focused state on the site.&lt;/p&gt;

&lt;p&gt;When I was new to HTML I used to disable the default focus state of links, buttons, and inputs on the website because they don't look so good. Later on, I realized that they serve their purpose.&lt;/p&gt;

&lt;p&gt;In the CSS file, you'll see that I have disabled the focus style.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Figrkkk2n27wzq7lbu5hu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Figrkkk2n27wzq7lbu5hu.png" alt="removed outline style on focus"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Instead of just removing the focus style we can change it. For this example, I'll use a border style.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxqxgdntjcghct3si3uyc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxqxgdntjcghct3si3uyc.png" alt="updated focus style code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now if we try navigating with the keyboard you can see the links are selected when they're focused. I think this looks better. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmy2miwvmdeg4809gf9lu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmy2miwvmdeg4809gf9lu.png" alt="focused link style on website"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Great!, if we continue navigating through the keyboard you might notice a part that was skipped that shouldn't be, that's the the previous and next icons.  Did you notice it? 👀. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9sfdhrstqzlvdbd3bfxk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9sfdhrstqzlvdbd3bfxk.png" alt="previous and next slider icons"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Keyboard users should be able to access that section because it's a CTA button to move the slider. So let's fix this: &lt;br&gt;
There are multiple fixes for this but the simplest fix is to warp a button around the element.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxy9rwlekkpt707p70fo2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxy9rwlekkpt707p70fo2.png" alt="Updated a11y fix"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Test the site again, the keyboard navigation is fantastic.&lt;/p&gt;

&lt;h3&gt;
  
  
  Form test
&lt;/h3&gt;

&lt;p&gt;The subscribe form at the footer looks okay and it could probably pass for accessibility since it is a form with one input.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the placeholder is acting as a label (This might pass in this case but if you have multiple inputs then a user might forget what they're supposed to fill into a particular form because there's no label)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To fix this let's add a label to the input and change the placeholder text.&lt;/p&gt;

&lt;p&gt;We can also improve the experience of this form by adding an autocomplete to the input field. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1uzgxnnu58avbooc907g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1uzgxnnu58avbooc907g.png" alt="updated form code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the image above, I have also added a form title and added &lt;strong&gt;(required)&lt;/strong&gt; to the label to let the user know it is required.&lt;/p&gt;

&lt;p&gt;Here's the &lt;a href="https://codepen.io/leezee/pen/NWoPWmj" rel="noopener noreferrer"&gt;updated pen&lt;/a&gt; for manual testing of our webpage.&lt;/p&gt;

&lt;p&gt;We have improved the experience of this webpage and it's accessible!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/XROOE9NApITmCgF6dZ/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/XROOE9NApITmCgF6dZ/giphy.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;There are several other aspects to consider when testing a website beyond the ones covered in this article. When developing a functional site, it's important to test transitions and animations. Depending on the type of animation, it may be necessary to use reduced motion and ensure it functions properly. Additionally, it's a good idea to test font sizes to ensure that users with blurred vision can still read the text on the site without difficulty.&lt;/p&gt;




&lt;p&gt;Thank you so much for reading. I hope you found this article helpful, If you did please like and share with anyone who might also find this useful.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>a11y</category>
      <category>frontend</category>
    </item>
    <item>
      <title>A beginner's guide to building an accessible website</title>
      <dc:creator>Elizabeth</dc:creator>
      <pubDate>Tue, 10 Oct 2023 13:23:16 +0000</pubDate>
      <link>https://dev.to/ilizette/a-beginners-guide-to-building-an-accessible-website-32fj</link>
      <guid>https://dev.to/ilizette/a-beginners-guide-to-building-an-accessible-website-32fj</guid>
      <description>&lt;h2&gt;
  
  
  Why a11y is important to me as a developer
&lt;/h2&gt;

&lt;p&gt;As someone who suffers from chronic migraines, I am particularly sensitive to bright colors, which can trigger migraines. Navigating applications without a dark mode option can &lt;strong&gt;sometimes&lt;/strong&gt; pose a bit of a challenge for me, especially when I need to use them for extended periods. &lt;br&gt;
As I progressed in my development career, I became acquainted with web accessibility, It dawned on me that there are individuals who face persistent challenges accessing applications not just sometimes, but &lt;strong&gt;every time&lt;/strong&gt; because their unique needs have been overlooked.&lt;/p&gt;

&lt;p&gt;This realization led me to educate myself about disabilities and it became clear to me that every day is not always straightforward for people with disabilities. As a developer, I believe it is my responsibility to make sure that I create applications that are convenient for everyone, including people living with disabilities.&lt;/p&gt;
&lt;h2&gt;
  
  
  Tips for building an accessible Platform
&lt;/h2&gt;

&lt;p&gt;Using the appropriate semantic elements in HTML can act as a guide for visually impaired users to navigate a website. HTML provides a lot of semantic elements, and it is crucial to use them properly. Some types of semantic elements include:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/li"&gt;List items&lt;/a&gt;:&lt;/strong&gt; When used correctly, HTML lists group-related elements and helps users with screen readers better understand the information presented. Examples are:&lt;br&gt;
 &lt;code&gt;&amp;lt;ul&amp;gt;, &amp;lt;ol&amp;gt;, &amp;lt;dl&amp;gt;, &amp;lt;li&amp;gt;, &amp;lt;menu&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Learn/HTML/Introduction_to_HTML/Document_and_website_structure"&gt;Body structure&lt;/a&gt;:&lt;/strong&gt; Instead of using &lt;code&gt;divs&lt;/code&gt; to separate every section of your website, use the semantic element to give structure to your website or web application. Examples of the body structure include &lt;code&gt;&amp;lt;header&amp;gt;, &amp;lt;footer&amp;gt;, &amp;lt;main&amp;gt;. &amp;lt;nav&amp;gt;, &amp;lt;section&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Accessible attributes: HTML attributes are very important when building accessible web platforms. They can give more information about an element, especially for people using screen readers to access your platform. Some web-accessible attributes are: &lt;a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA"&gt;aria&lt;/a&gt;, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel"&gt;rel&lt;/a&gt;, alt, role, title, and so on. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;alt&lt;/strong&gt;: The &lt;code&gt;alt&lt;/code&gt; attribute is an important tag in HTML that provides more information about the images used on a webpage. It is used by screen readers to describe the image to users. It is recommended to keep the alt text brief and to the point. If the image is purely decorative, then the alt tag should be left blank. Avoid using phrases like "image of" or "photo of" in the alt text, as these are already interpreted by screen readers.&lt;/p&gt;

&lt;p&gt;An example of a descriptive image: &lt;code&gt;&amp;lt;img scr="cat.png" alt="a smiling cat" /&amp;gt;&lt;/code&gt;&lt;br&gt;
An example of a decorative image: &lt;code&gt;&amp;lt;img scr="arrow.svg" alt="" /&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I created an image component in my React app using typescript to ensure that I always provide an alt text. I made it mandatory to pass the alt as a prop, so if I ever forget to add the alt attribute to my image, typescript throws an error and reminds me to add it.&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface ImageInterface extends HTMLAttributes&amp;lt;HTMLImageElement&amp;gt; {
  src: string;
  alt: string;
}

export const Image: React.FC&amp;lt;ImageInterface&amp;gt; = ({ src, alt, ...rest }) =&amp;gt; (
  &amp;lt;img
    src={src}
    alt={alt}
    {...rest}
  /&amp;gt;
);

export default Image;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;role&lt;/strong&gt;: The 'role' attribute does exactly what it says—it tells browsers and screen readers what an element does. It's like giving an element a specific job title. Always use the most fitting role possible, and avoid using generic roles like 'group' unless it's really necessary. Also, don't double up on roles; if something already has a clear description, let it be. e.g&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Here is a wrong use of role: 
`&amp;lt;button role="button"&amp;gt;Click me&amp;lt;/button&amp;gt;`. 
// You're already using a button you do not need to add a role.


//This is a valid example of using the role: 
`&amp;lt;div role="button"&amp;gt;
This div is now acting as a button
&amp;lt;/div&amp;gt;`

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Keyboard Navigation.
&lt;/h3&gt;

&lt;p&gt;When creating a web page or component, I prioritize smooth keyboard navigation to ensure a seamless user experience. If I encounter any challenges in navigating with a keyboard, I revisit my code and make the required adjustments. It's important to remember that some users rely solely on their keyboards to interact with your applications. Neglecting to test and optimize for keyboard navigation can create barriers for these users, hindering their experience with your platform. Therefore, it is crucial to ensure that keyboard navigation is seamless and user-friendly for all users. &lt;/p&gt;

&lt;h3&gt;
  
  
  Accessible Colors
&lt;/h3&gt;

&lt;p&gt;I have visited some websites where it was quite difficult for me to navigate due to the color scheme. If you are not someone with a permanent color vision issue it is still important to understand how people perceive color and contrast. This will help you understand how to best support their visual needs.&lt;/p&gt;

&lt;p&gt;For a comprehensive understanding of the color system and accessibility, refer to &lt;a href="https://m3.material.io/styles/color/the-color-system/accessibility"&gt;this article by material.io.&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;When working with colors it is important to understand the CSS media &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme"&gt;@prefers-color-scheme&lt;/a&gt; and  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-contrast"&gt;@prefers-contrast&lt;/a&gt;. The linked MDN articles offer detailed insights on how to effectively utilize these features.&lt;/p&gt;

&lt;h2&gt;
  
  
  Animations
&lt;/h2&gt;

&lt;p&gt;Web accessibility goes beyond using correct HTML codes; it also involves considering the impact of animations on users. Personally, as someone prone to migraines, certain animations can trigger dizziness for me. If you've experienced motion sickness, be it in a car or on a boat, you can relate.&lt;/p&gt;

&lt;p&gt;To address this concern, the @prefers-reduced-motion CSS media query comes into play. It checks whether users have enabled a setting on their device to minimize the amount of motion they experience.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.animated-element {
  animation: swing 1s linear infinite alternate;
}

@media (prefers-reduced-motion) {
  .animated-element {
    animation: none;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is also important to avoid flashing content which can be particularly frustrating for users with photosensitivity, frequent flashes also have the potential to trigger seizures.&lt;/p&gt;

&lt;p&gt;In cases where flashing content is unavoidable, it's imperative to include a Flash Warning alert on your platform. This proactive approach ensures users are informed and can take necessary precautions while engaging with the content.&lt;/p&gt;

&lt;h3&gt;
  
  
  Forms
&lt;/h3&gt;

&lt;p&gt;When you're working with form elements and attributes, the default elements have very good accessibility support. But sometimes the styles are not very pretty and uniform across different browsers and we might need to create custom form styles. when building custom forms, it's essential to prioritize accessibility.&lt;/p&gt;

&lt;p&gt;Ensuring that custom styles maintain accessibility standards is crucial. This guarantees that, despite the visual enhancements, users of all abilities can seamlessly interact with and navigate through the form.&lt;/p&gt;

&lt;p&gt;Always add a focus style for your form so a keyboard user knows which field they're currently on, the HTML input element already has a focus style using an outline, I personally don't like that style so using &lt;a href="https://tailwindcss.com/docs/hover-focus-and-other-states#focus"&gt;tailwind&lt;/a&gt; I would usually replace it with something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;input class="focus:outline-none focus:ring-1 focus:ring-slate-400" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Labels:&lt;/strong&gt; They are used to inform a user about the purpose of an input field. Do not replace the labels with placeholders as they serve different purposes. If a field is required a good practice is to add that to the label.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;label&amp;gt;Email address: 
&amp;lt;span&amp;gt;(required)&amp;lt;/span&amp;gt;
&amp;lt;input id="email" type="email" autocomplete="email" required /&amp;gt;
&amp;lt;/label&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Error handling:&lt;/strong&gt; When a user encounters a form error, we need to make the error known to the user in the simplest way possible, and offer suggestions on how to fix the error. &lt;/p&gt;

&lt;h2&gt;
  
  
  More accessibility tips:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Use the appropriate semantic elements (e.g: don't replace your button with a div)&lt;/li&gt;
&lt;li&gt;Use appropriate attributes where required (e.g alt, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex"&gt;tabindex&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Use common fontface whenever possible.&lt;/li&gt;
&lt;li&gt;Use relative values for your base font sizes (e.g. %, rem) to allow easy resizing.&lt;/li&gt;
&lt;li&gt;Avoid using justified paragraph alignment &lt;code&gt;text-align: justify;&lt;/code&gt;, It can create uneven spacing between texts.&lt;/li&gt;
&lt;li&gt;Add captions or transcripts to videos &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In my next article, we'll look at how to test your website for accessibility. &lt;/p&gt;

&lt;p&gt;If you found this article helpful, please like and consider sharing it with others who may also benefit.&lt;/p&gt;

</description>
      <category>inclusion</category>
      <category>frontend</category>
      <category>a11y</category>
      <category>beginners</category>
    </item>
    <item>
      <title>A guide to web accessibility (A11y)</title>
      <dc:creator>Elizabeth</dc:creator>
      <pubDate>Wed, 24 May 2023 09:03:59 +0000</pubDate>
      <link>https://dev.to/ilizette/a-guide-to-web-accessibility-a11y-57od</link>
      <guid>https://dev.to/ilizette/a-guide-to-web-accessibility-a11y-57od</guid>
      <description>&lt;p&gt;Have you ever attempted to navigate a website solely using your keyboard due to a trackpad malfunction or simply by choice, only to discover that certain functions cannot be performed without a mouse or trackpad?&lt;/p&gt;

&lt;p&gt;Have you ever experienced a temporary physical limitation, rendering your arm unusable and making the navigation of certain applications or websites excessively complicated?&lt;/p&gt;

&lt;p&gt;If your answer is affirmative, I sincerely apologize for any inconvenience caused, and I can empathize with the frustration you must have felt.&lt;/p&gt;

&lt;p&gt;It is important to recognize that individuals with permanent disabilities may encounter difficulties when attempting to use certain applications and websites. In fact, a significant number of applications overlook their needs.&lt;/p&gt;

&lt;p&gt;I must admit that I have been at fault for developing applications and websites without fully considering the accessibility requirements of all users and while that is changing I know there's still a lot to learn but I'll share what I know so far here in this article.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Web Accessibility?
&lt;/h2&gt;

&lt;p&gt;Web accessibility, often referred to as a11y  (a &lt;a href="https://www.collinsdictionary.com/submission/22655/numeronym"&gt;numeronym&lt;/a&gt; for "accessibility"), entails constructing a web platform that ensures seamless interaction for individuals with disabilities, granting them an equivalent user experience to that of others.&lt;/p&gt;

&lt;p&gt;Throughout this article, I may use the terms "Web Accessibility" and "a11y" interchangeably.&lt;/p&gt;

&lt;p&gt;Disabilities come in various forms, some of which have a greater impact on digital interactions than others. It is crucial to consider the needs of all individuals, irrespective of their disabilities, and incorporate accessibility best practices at every stage of your product's lifecycle, encompassing planning, design, and implementation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Types of Disabilities
&lt;/h3&gt;

&lt;p&gt;Disabilities can impact individuals in various ways, even if they share the same type of disability. Additionally, certain disabilities may not be immediately apparent. Here are some examples of disabilities that can affect individuals:&lt;/p&gt;

&lt;h4&gt;
  
  
  Visual impairments:
&lt;/h4&gt;

&lt;p&gt;These include blindness, color blindness, blurred vision, low vision, and night blindness. People who are visually impaired commonly use screen readers, magnifying tools, or text-to-speech software as an assistive tool.&lt;/p&gt;

&lt;h4&gt;
  
  
  Hearing impairments:
&lt;/h4&gt;

&lt;p&gt;This category encompasses individuals who are partially or completely deaf. Commonly used assistive tools for individuals with hearing impairments include hearing aids, video captions, and video transcripts.&lt;/p&gt;

&lt;h4&gt;
  
  
  Cognitive impairments:
&lt;/h4&gt;

&lt;p&gt;This can manifest as developmental delays, dementia, ADHD, or autism. Individuals with cognitive impairments usually use text prediction or screen readers as an assistive tool.&lt;/p&gt;

&lt;h4&gt;
  
  
  Mobility impairments:
&lt;/h4&gt;

&lt;p&gt;This category includes individuals with amputations, arthritis, or spinal cord injuries. Individuals with mobility impairments might use speech input, adaptive keyboards, and braille notetakers as assistive tools.&lt;/p&gt;

&lt;h4&gt;
  
  
  Speech impairments:
&lt;/h4&gt;

&lt;p&gt;This category encompasses conditions such as stuttering or articulation errors. Some individuals with speech impairments might use speech-generating devices or electronic fluency devices as an assistive tool&lt;/p&gt;

&lt;p&gt;You can read more about the different types of disability &lt;a href="https://www.disabled-world.com/disability/types/"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's worth mentioning that accessibility (a11y) goes beyond benefiting people with disabilities. There are others who can also reap the rewards of an accessible platform. As an example, I personally experience migraines, and when I encounter a platform without a dark mode option, it becomes difficult for me to use.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why is Web Accessibility Important?
&lt;/h2&gt;

&lt;p&gt;Web accessibility is important as it guarantees equal access and usability of web platforms for people with disabilities. In today's world, the web serves as a vital platform for communication, information sharing, e-commerce, and accessing various services. It plays an essential role in our daily lives, and everyone must have the opportunity to fully engage in the digital world.&lt;/p&gt;

&lt;p&gt;Here are some key reasons why web accessibility is important:&lt;/p&gt;

&lt;h3&gt;
  
  
  Website traffic impact:
&lt;/h3&gt;

&lt;p&gt;An accessible website helps you reach a wider audience, when you make provision for everyone using your platform you encourage greater engagement from the visitors to your website, resulting in increased website traffic.&lt;/p&gt;

&lt;h3&gt;
  
  
  Inclusion and Equal Opportunity:
&lt;/h3&gt;

&lt;p&gt;Web accessibility fosters inclusivity by eliminating obstacles and ensuring equitable access to information and services. It empowers individuals with disabilities to navigate and engage with websites efficiently, enabling their active involvement in education, employment, e-commerce, social interactions, and various facets of society, just like everyone else.&lt;/p&gt;

&lt;h3&gt;
  
  
  Better Website SEO:
&lt;/h3&gt;

&lt;p&gt;Many SEO guidelines are in line with accessibility (a11y) guidelines, such as using alt text and employing proper headings. By making your website inclusive, SEO crawlers can easily comprehend your platform.&lt;/p&gt;

&lt;h3&gt;
  
  
  Legal impact:
&lt;/h3&gt;

&lt;p&gt;In certain regions like the EU, Canada, Japan, and the UK, there is a legal requirement to ensure accessibility for your platform. You can learn more about these requirements &lt;a href="https://www.w3.org/WAI/policies/"&gt;here&lt;/a&gt;. Adhering to accessibility standards not only makes sense for your business in terms of compliance but also reduces the risk of potential lawsuits.&lt;/p&gt;

&lt;p&gt;However, avoiding legal issues or personal benefits should not be the sole motivation for focusing on website accessibility. As developers and designers, it is our responsibility to ensure that all users have a positive experience, regardless of the means they choose to access our platform. Let's prioritize accessibility because we have to create an inclusive environment for everyone.&lt;/p&gt;

&lt;h2&gt;
  
  
  Accessibility Principles
&lt;/h2&gt;

&lt;p&gt;The W3C (World Wide Web Consortium) has established a set of &lt;a href="https://www.w3.org/WAI/fundamentals/accessibility-principles/#standards"&gt;accessibility requirements&lt;/a&gt; for digital platforms and tools, which are recognized internationally as the standard for web accessibility. These principles ensure that your platform offers:&lt;/p&gt;

&lt;h3&gt;
  
  
  Perceivable information:
&lt;/h3&gt;

&lt;p&gt;This principle ensures that your users can perceive all essential information displayed on the screen. It involves providing text alternatives for non-text content. You can do this by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Adding descriptive alt text to images&lt;/li&gt;
&lt;li&gt;Using action words for icons, such as "Next" for a next arrow icon in a carousel&lt;/li&gt;
&lt;li&gt;Including captions or transcripts for videos&lt;/li&gt;
&lt;li&gt;Applying labels to form inputs&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Operable user interface
&lt;/h3&gt;

&lt;p&gt;This principle ensures that your users can effectively operate your platform, locate content, and have sufficient time to read and interact with the content. You can make your platform operable by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Providing a keyboard alternative for mouse events&lt;/li&gt;
&lt;li&gt;Allowing users enough time to fill out forms or read content&lt;/li&gt;
&lt;li&gt;Providing controls for your videos&lt;/li&gt;
&lt;li&gt;Ensuring that keyboard focus is visibly indicated&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Understandable information
&lt;/h3&gt;

&lt;p&gt;This means that your users should be able to understand the information on your platform including content read by text-to-speech. examples of these include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Using clear and concise error messages&lt;/li&gt;
&lt;li&gt;Specifying the language of text content&lt;/li&gt;
&lt;li&gt;Using plain and straightforward language, providing definitions for unfamiliar terms&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Robust content
&lt;/h3&gt;

&lt;p&gt;This principle ensures that your platform is compatible with various browsers and assistive technologies like screen readers. Examples of following this principle include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Testing your platform using only the keyboard or a screen reader to verify accessibility&lt;/li&gt;
&lt;li&gt;Creating a responsive platform that adapts well to different screen sizes and devices&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It's important to recognize that building an accessible platform goes beyond mere compliance with rules or the fear of legal repercussions. It's about guaranteeing that your platform is accessible to all individuals who have internet access and enhancing their overall web experience.&lt;/p&gt;

&lt;p&gt;In my next article, I'll be sharing some a11y guidelines I follow when building a website or web app.&lt;/p&gt;

&lt;p&gt;If you liked this article kindly tap the heart icon and share it with others who might like it.&lt;/p&gt;

&lt;p&gt;Please be aware that this article intends to provide information. If you come across any inaccuracies or misinformation in this article, please feel free to contact me or leave a comment in the section below, and I will gladly review it. Thank you.&lt;/p&gt;

&lt;p&gt;Resources:&lt;br&gt;
&lt;a href="https://www.w3.org/WAI/tutorials/images/decision-tree/"&gt;https://www.w3.org/WAI/tutorials/images/decision-tree/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.w3.org/WAI/fundamentals/accessibility-principles/"&gt;https://www.w3.org/WAI/fundamentals/accessibility-principles/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>a11y</category>
      <category>webdev</category>
      <category>web</category>
      <category>inclusion</category>
    </item>
    <item>
      <title>My open-source experience via SCA Contributhon</title>
      <dc:creator>Elizabeth</dc:creator>
      <pubDate>Wed, 28 Apr 2021 16:42:01 +0000</pubDate>
      <link>https://dev.to/ilizette/my-open-source-experience-via-sca-contribution-lbk</link>
      <guid>https://dev.to/ilizette/my-open-source-experience-via-sca-contribution-lbk</guid>
      <description>&lt;p&gt;This month has been exciting for me, I got into open-source via the &lt;a href="https://layer5.io/programs/sca-contributhon"&gt;contributhon by She Code Africa&lt;/a&gt; program, which made it less difficult for me to understand what needs to be done. I will be sharing a summary of my experience and currently merged PRs in this post.&lt;/p&gt;

&lt;h1&gt;
  
  
  My Experience
&lt;/h1&gt;

&lt;p&gt;When I got a mail from SCA (She Code Africa) that I was part of the selected participant for the program, I felt so excited and scared at the same time because I used to think open-source was for some special set of people😅&lt;/p&gt;

&lt;p&gt;I had the opportunity to contribute to &lt;a href="https://layer5.io/"&gt;Layer5&lt;/a&gt; as a frontend developer. Because it was a program from SCA we were assigned to mentors and a person of contact.&lt;/p&gt;

&lt;p&gt;The mentors assigned to my team were &lt;a href="https://layer5.io/community/members/jash-patel"&gt;Jash Patel&lt;/a&gt; and &lt;a href="https://layer5.io/community/members/chinmay-mehta"&gt;Chinmay Mehta&lt;/a&gt; and &lt;a href="https://layer5.io/community/members/ruth-ikegah"&gt;Ruth Ikegah&lt;/a&gt; was our person of contact for the program.&lt;/p&gt;

&lt;p&gt;The Layer5 team has several repositories and all I just had to do is find an issue I am interested in working on and then asking for it to be assigned to me.&lt;/p&gt;

&lt;h2&gt;
  
  
  Making contributions
&lt;/h2&gt;

&lt;p&gt;Once I found an issue I could work on (it is usually recommended to select a beginner's friendly issue), I comment on the issue asking for it to be assigned to me to work, once it has been assigned and worked on, we were required to "sign off" our commits. That was the first time I was hearing about signing off a commit and I decided to read up on what it means.&lt;br&gt;
In summary - The purpose of "--sign-off" is to track who made a particular change or added a feature.&lt;/p&gt;

&lt;p&gt;Here's an example of signing off a commit&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git commit --sign-off -m "fixed a footer glitch"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;here's how it'll look like in a PR&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flrkxgd9qfkvwttxxjyfo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flrkxgd9qfkvwttxxjyfo.png" alt="image" width="800" height="152"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After pushing the commit and creating a pull request, two of the site maintainers will need to approve the work before it's been pushed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Attending community meetings
&lt;/h2&gt;

&lt;p&gt;Every week we attended community meetings to discuss new issues or features, welcome and onboard newcomers, and discuss recent changes. Personally, I pick issues during these meetings.&lt;/p&gt;

&lt;h2&gt;
  
  
  The community
&lt;/h2&gt;

&lt;p&gt;The slack channel is where every other thing happens. This is actually the first time I will be among a very diverse team.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This is one of the many things I will come to like about open source&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Personally, I felt welcomed in the community, I can freely ask any question when I got stuck or even share something new.&lt;/p&gt;

&lt;h1&gt;
  
  
  Project Report Details
&lt;/h1&gt;

&lt;h3&gt;
  
  
  Summary of work done
&lt;/h3&gt;

&lt;p&gt;I currently have two pull requests merged in the layer5 meshery.io repository. &lt;/p&gt;

&lt;p&gt;Here's a link to a document that &lt;a href="https://docs.google.com/document/d/1l3IFXp80jHzOh1VgrIiJuyZV4HPHHrvupqySmD5RjZA/edit?usp=sharing"&gt;summarizes the work done&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I currently have some pull requests waiting for approval and I'll be updating them as soon as they're merged.&lt;/p&gt;

&lt;h3&gt;
  
  
  Challenges faced
&lt;/h3&gt;

&lt;p&gt;My major challenge was when I always forget to sign off my commit. 😅&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/U5U2vQtGn2C5qdBAHK/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/U5U2vQtGn2C5qdBAHK/giphy.gif" alt="Typical gif" width="600" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I also had issues jumping into the codebase to make changes, because I had no form of experience with Jekyll. However, the community was helpful with that. I asked questions and got valid and detailed answers. I also wasn't very familiar with gatsby but a stack overflow was really helpful.&lt;/p&gt;

&lt;h3&gt;
  
  
  Lessons learnt
&lt;/h3&gt;

&lt;p&gt;One of my favorite lessons was realizing how easy anything can be if I put my mind to it. I used to think open-source was for professionals with over 10 years of experience in tech. It sounds so absurd thinking of it now😂&lt;/p&gt;

&lt;p&gt;I also understand why it is important to write clean code because if Layer5's codebase was complicated it would have been very difficult for me to jump into the codebase and start editing.&lt;/p&gt;

&lt;p&gt;Jekyll and Gatsby are now familiar to me.&lt;/p&gt;

&lt;h1&gt;
  
  
  Next Steps
&lt;/h1&gt;

&lt;p&gt;The last few weeks in April have been amazing for me or The past month has been amazing for me and I really look forward to making more contributions to layer5 and other open-source communities later on. Open source is amazing and what's even cooler is that great feeling you get when the maintainers approve your pull requests.&lt;/p&gt;

</description>
      <category>opensource</category>
    </item>
    <item>
      <title>Creating a custom hook in React</title>
      <dc:creator>Elizabeth</dc:creator>
      <pubDate>Fri, 12 Mar 2021 22:44:13 +0000</pubDate>
      <link>https://dev.to/ilizette/creating-a-custom-hook-in-react-lec</link>
      <guid>https://dev.to/ilizette/creating-a-custom-hook-in-react-lec</guid>
      <description>&lt;p&gt;Hello there, thank you for your feedback and comments during this series, We've covered the main hooks provided by React, in my last post we covered useReducer. We'll be looking at how to create a custom hook and some rules to follow. Let's jump right in.&lt;/p&gt;

&lt;h1&gt;
  
  
  Why would I need a custom hook?
&lt;/h1&gt;

&lt;p&gt;There are many reasons why you'd want to create your custom hook, but the ultimate purpose of custom hooks is to reuse any hook-related logic all across your app. React is all about reusability as we all know.&lt;/p&gt;

&lt;p&gt;Before we continue let's go back to the beginning of this series where we talked about the rules of hooks&lt;/p&gt;

&lt;h3&gt;
  
  
  What are the rules of using hooks
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Don't call hooks inside of a loop or conditional statements, or nested functions only call them at top levels&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You can only call hooks in functional components or inside of another hook&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;React has an  &lt;a href="https://www.npmjs.com/package/eslint-plugin-react-hooks"&gt;eslint-plugin&lt;/a&gt; that enforces these rules.&lt;/p&gt;

&lt;p&gt;I think it's best to add this last one also, this applies to when creating a custom hook.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Always prefix your custom hook name with &lt;code&gt;use&lt;/code&gt; so that React compiler will always check if the rules of hooks were applied.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Let us create our custom hook!
&lt;/h3&gt;

&lt;p&gt;We will be creating a hook that gets the size of a screen and returns it.&lt;/p&gt;

&lt;p&gt;First, we'll create a file named &lt;code&gt;useWindowSize.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useMemo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useCallback&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// We can react hooks in our custom hook&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isWindowType&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;object&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;useWindowSize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;isClient&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;isWindowType&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getSize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useMemo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;isClient&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHeight&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;isClient&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerWidth&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;}),&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;isClient&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// useMemo because it could cause unnecessary rerender&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;windowSize&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setWindowSize&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;getSize&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleResize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useCallback&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;setWindowSize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;getSize&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;},[&lt;/span&gt;&lt;span class="nx"&gt;getSize&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

    &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;isClient&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;resize&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;handleResize&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;resize&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;handleResize&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;windowSize&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;useWindowSize&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You'd notice that a custom hook is just like a regular javascript function, except you can use react hooks in them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; I could as well use this example in my component but I am creating it as a custom component because I would want to use this across multiple components in my project.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using a custom hook
&lt;/h3&gt;

&lt;p&gt;We use a custom hook the same way we use other hooks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;useWindowSize&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./useWindowSize&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// import the hook&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;width&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useWindowSize&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="c1"&gt;// Use it like you would use a react hook&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;It&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;s a small screen&amp;lt;/div&amp;gt;
      ) : (
        &amp;lt;div&amp;gt;It&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="nx"&gt;not&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;small&lt;/span&gt; &lt;span class="nx"&gt;screen&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="p"&gt;)}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/white-butterfly-idfkb"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Congratulations! you've just created a custom hook in react. Now that we're done with this article, how can you put what we've learned into action? Go ahead, explore and come up with something. Don't forget that you're allowed to make mistakes and it's perfectly normal to get errors.&lt;/p&gt;

&lt;p&gt;Did this article help you in any way? If it did give a like and follow me for more content like this. If you have any questions or comments please post them in the comment section below. Thanks a lot for reading. Keep being amazing and don't forget to be safe out there.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Nevertheless, Elizabeth Damilola keeps coding</title>
      <dc:creator>Elizabeth</dc:creator>
      <pubDate>Fri, 12 Mar 2021 16:51:16 +0000</pubDate>
      <link>https://dev.to/ilizette/nevertheless-elizabeth-damilola-keeps-coding-3hd5</link>
      <guid>https://dev.to/ilizette/nevertheless-elizabeth-damilola-keeps-coding-3hd5</guid>
      <description>&lt;p&gt;I have been inspired by a lot of amazing stories I've been reading. As women, no matter how different all have similar experiences based on our gender. We've been treated like second-class citizens and when we speak up (especially in the part of the world where I am from) we aren't taken seriously.&lt;/p&gt;

&lt;h2&gt;
  
  
  My coding journey
&lt;/h2&gt;

&lt;p&gt;I attended a coding school, here in Lagos to study Software engineering and get a diploma. We were just a few ladies in the whole school, four females in my class. And we were just two who really wanted to pursue a career in tech. However, it was automatically assumed that I would not be able to catch up. I was told by both the trainers and male classmates that I would quit because "Women aren't designed to be in tech". And some even took their time to explain what I could study if I want to be in tech. I was constantly told things like&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;As a lady you could study digital marketing. It's not that difficult.&lt;/p&gt;

&lt;p&gt;Ladies don't do Java, you can do graphics design and be a UI designer.&lt;/p&gt;

&lt;p&gt;Just learn WordPress it's what most ladies do&lt;/p&gt;

&lt;p&gt;I can build a blog for you, and you can start blogging. A lot of ladies do that.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Because of these statements and more, I decided to prove them wrong and this led me to study harder and always want to be the best in whatever tasks was given to us in class. This worked, I was picked as my team lead for my final project in my semester because I was one of the best in my class. But that didn't stop it. No matter how hard I tried I was always treated as an afterthought.&lt;/p&gt;

&lt;p&gt;I pressured myself to not make any mistake because if I did my male peers will make it seem like it was a gender thing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Workplace experiences
&lt;/h2&gt;

&lt;p&gt;I was employed as a developer in a company but because of my gender, I was also asked to take up the role of writing minutes in meetings.&lt;/p&gt;

&lt;p&gt;I offered to mentor new interns at a place of work, but all the interns were male and didn't want a female to mentor them because they "women don't really know much".&lt;/p&gt;

&lt;p&gt;Whenever I brought up the topic of equality it was quickly discarded because according to the managers "It's not a problem in Africa".&lt;/p&gt;

&lt;p&gt;I once applied for a job and after passing all the interview process I was offered a lower salary because "Ladies don't really spend their money".&lt;/p&gt;

&lt;p&gt;I have joined teams where I was the only female and it was automatically assumed that I am not very good. I had to always work extra hard to prove that I am good because of my gender.&lt;/p&gt;

&lt;h3&gt;
  
  
  Concern
&lt;/h3&gt;

&lt;p&gt;In all of my time coding, I have seen women quit programming, not because coding is too hard, but because they were told that they would never be good enough.&lt;/p&gt;

&lt;p&gt;The issue of gender equality cannot be overstressed especially in Africa. It's worrying that a lot of people still don't see it as an issue and in Africa, women still aren't taken seriously.&lt;/p&gt;

&lt;h3&gt;
  
  
  My advice for allies to support equality in tech is
&lt;/h3&gt;

&lt;p&gt;If you know an African lady who wants to code, offer to be her cheerleader and ask her to join (She Code Africa)[&lt;a href="https://www.shecodeafrica.org/"&gt;https://www.shecodeafrica.org/&lt;/a&gt;]&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;I keep coding because I want to and I deserve every chance and opportunity, I keep coding because I am a woman who can decide whatever I want, I keep coding because I freaking can. And I will keep coding and be a cheerleader to other women who are trying to find their way in tech.&lt;/p&gt;

</description>
      <category>choosetochallenge</category>
      <category>wecoded</category>
    </item>
    <item>
      <title>Understanding useReducer in react</title>
      <dc:creator>Elizabeth</dc:creator>
      <pubDate>Fri, 05 Mar 2021 19:14:27 +0000</pubDate>
      <link>https://dev.to/ilizette/understanding-usereducer-in-react-39ie</link>
      <guid>https://dev.to/ilizette/understanding-usereducer-in-react-39ie</guid>
      <description>&lt;p&gt;Hi there, in my last post we covered &lt;code&gt;useCallback&lt;/code&gt; in react, and now, we'll be looking at one last hook provided to us by the amazing React team: &lt;code&gt;useReducer&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  What is the useReducer hook?
&lt;/h1&gt;

&lt;p&gt;Before we continue to explain what the hook is all about let's take a step back and look at what a reducer is.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a reducer
&lt;/h2&gt;

&lt;p&gt;If you are familiar with redux then you'd know what a reducer function is.&lt;/p&gt;

&lt;p&gt;A reducer accepts a state and an action as an argument and returns a new state as a result. Here's a common example of a reducer&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;initialState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;loading&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;names&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;reducer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;initialState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;switch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;loading&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;loading&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;error&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;loading&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;success&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;names&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;payload&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="nl"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;What is going on here?&lt;/strong&gt;&lt;br&gt;
The function above is checking for a type and returning a state based on the type that was passed.&lt;/p&gt;
&lt;h2&gt;
  
  
  Back to useReducer
&lt;/h2&gt;

&lt;p&gt;The useReducer hook is very similar to the useState hook, it allows you to manage a state and rerender the component whenever your state changes, It accepts a reducer and an initial state (like the example above) and returns a new version of the state and a dispatch method based on the action performed in the reducer.&lt;/p&gt;

&lt;p&gt;Here is an example of how it is being used:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useReducer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;reducer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;initialState&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The hook also takes a third argument that will lazily initialize the state or reset the state back to its initial state. You can read more on the lazy initialization in &lt;a href="https://reactjs.org/docs/hooks-reference.html#lazy-initialization" rel="noopener noreferrer"&gt;react documentation&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useReducer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;reducer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;initialState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;initFunc&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Why should I use this?
&lt;/h3&gt;

&lt;p&gt;The useReducer hook is often used when you have a complex state, or where the initial state is dependent on another state.&lt;/p&gt;

&lt;p&gt;To understand this better, we need some actions. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia3.giphy.com%2Fmedia%2F26DOMQa5Ib2SmaRZm%2Fgiphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia3.giphy.com%2Fmedia%2F26DOMQa5Ib2SmaRZm%2Fgiphy.gif" alt="film scene gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Examples
&lt;/h4&gt;

&lt;p&gt;Let us look at a counter using useState&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;num1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setNum1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;decrement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setNum1&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;prev&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;prev&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;increment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setNum1&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;prev&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;prev&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nx"&gt;Num&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;num1&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;grid&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;box&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;+&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;num1&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;box&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;decrement&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="o"&gt;-&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/kind-ritchie-yoo60"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Now let's look at the same example using useReducer&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useReducer&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;initialState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;num&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;reducer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;switch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;increment&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;num&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;decrement&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;num&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="nl"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useReducer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;reducer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;initialState&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Num&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;grid&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;box&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;increment&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;})}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;+&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;box&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;decrement&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="o"&gt;-&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/adoring-wildflower-s09u8"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;In our reducer function, we're using the type to determine what action will be performed on the state.&lt;/p&gt;

&lt;p&gt;This method is better if we're creating a calculator for example.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;There's been a lot of arguments on whether to use the useState hook or useReducer, it actually depends on what you're doing but Kent C. Dodds gave very &lt;a href="https://kentcdodds.com/blog/should-i-usestate-or-usereducer" rel="noopener noreferrer"&gt;detailed examples on when to use either in his post&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Thank you so much for reading, In my next post we'll be looking at how to create our very own react hook.&lt;/p&gt;

&lt;p&gt;If you have any questions or comments please drop them in the comment below. Don't forget to stay safe and keep being amazing.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Understanding useCallback in react</title>
      <dc:creator>Elizabeth</dc:creator>
      <pubDate>Fri, 26 Feb 2021 19:18:07 +0000</pubDate>
      <link>https://dev.to/ilizette/understanding-usecallback-in-react-5d34</link>
      <guid>https://dev.to/ilizette/understanding-usecallback-in-react-5d34</guid>
      <description>&lt;p&gt;Hello there, so we have almost covered the most used hooks in Reactjs. In my last post, we talked about the &lt;code&gt;useRef&lt;/code&gt; hook. In this post, we'll be covering the &lt;code&gt;useCallback&lt;/code&gt; hook. So let's start right away.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is the useCallback hook
&lt;/h1&gt;

&lt;p&gt;Use callback is a hook that returns a memoized callback function when one of the dependencies passed to it changes. &lt;/p&gt;

&lt;h3&gt;
  
  
  Wait! isn't that what useMemo does?
&lt;/h3&gt;

&lt;p&gt;Well, the short answer is NO! Although both hooks are memoizing something they're however returning completely different things. The useMemo hook returns a &lt;strong&gt;memoized value&lt;/strong&gt; while useCallback returns a &lt;strong&gt;memoized function&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia.tenor.com%2Fimages%2Fe10fb2d6819f9492ee87967c0daad827%2Ftenor.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia.tenor.com%2Fimages%2Fe10fb2d6819f9492ee87967c0daad827%2Ftenor.gif" alt="Relief meme"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Why &lt;code&gt;useCallbacks&lt;/code&gt;?
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;useCallback&lt;/code&gt; hook is very useful when creating an application where some of the functions created are complex and re-rendering the component might make such function run which we don't want, probably because it might slow down the run time.&lt;/p&gt;

&lt;h3&gt;
  
  
  Let's see some actions
&lt;/h3&gt;

&lt;p&gt;This hook accepts a callback function (&lt;strong&gt;useCallback&lt;/strong&gt;) and a list of dependencies that makes the hook run when the value changes.&lt;/p&gt;

&lt;h5&gt;
  
  
  Basic usage
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useCallback&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;callbackVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useCallback&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="nf"&gt;functionCall&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
 &lt;span class="p"&gt;},[&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
You'd likely use the &lt;code&gt;useCallback&lt;/code&gt; hook alongside the &lt;a href="https://dev.to/ilizette/understanding-useeffects-and-usecontext-47ah"&gt;&lt;code&gt;useEffect&lt;/code&gt;&lt;/a&gt; hook. Sometimes to prevent a continuous re-rendering or infinite loop. Consider the example in the sandbox below.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/usecallbackreactexample-5k715"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;In the example above, I have 2 components I am working with, the &lt;code&gt;App.js&lt;/code&gt; file and the &lt;code&gt;Score.js&lt;/code&gt; file. The score component has a useEffect that is updating a state on props change and logging a message to the console.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Score&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;score&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;showScore&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setShowScore&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setShowScore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;score&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Component updating&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;score&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
   &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Score&lt;/span&gt; &lt;span class="na"&gt;here&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;showScore&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;   &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Score&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the &lt;code&gt;App.js&lt;/code&gt; file, we have a &lt;code&gt;clacScore&lt;/code&gt; function that is adding 5 to any score the user enters, an input field that allows a user to enter a player name, and a button to toggle the player name. Everything seems to work fine, doesn't it?&lt;/p&gt;

&lt;p&gt;There's a problem with our code. When we enter a player's name into our input field a message logs in the console and this also happens when we do anything at all on the page. This is a problem because we only want that message to display when we update the score.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;useCallback to the rescue&lt;/strong&gt;&lt;br&gt;
Try replacing the &lt;code&gt;clacScore&lt;/code&gt; function with the code below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;clacScore&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useCallback&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;scoreEntered&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;scoreEntered&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/frosty-firefly-fr1m8"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Now try entering a player name into the input box or showing the player name. And notice that the message in the console only displays when we change the score. This is because we're using the &lt;code&gt;useCallback&lt;/code&gt; hook to tell React to only render the &lt;code&gt;Score&lt;/code&gt; component when the &lt;code&gt;scoreEntered&lt;/code&gt; state is being updated. So the hook has actually helped us boost the performance of our little application.&lt;/p&gt;

&lt;h3&gt;
  
  
  When should I useCallback?
&lt;/h3&gt;

&lt;p&gt;So I'm sure we can agree that useCallback is awesome. However, that doesn't mean that we should start wrapping all our functions into a useCallback, remember that saying that goes:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Too much of everything isn't cool.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Yeah, that applies for &lt;code&gt;useCallback&lt;/code&gt; and &lt;code&gt;useMemo&lt;/code&gt; and &lt;code&gt;useAnything&lt;/code&gt; (wait! what?😅).&lt;/p&gt;

&lt;p&gt;So the useCallback hook should only be used when&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;We want to do &lt;a href="http://adripofjavascript.com/blog/drips/object-equality-in-javascript.html" rel="noopener noreferrer"&gt;referential equality&lt;/a&gt; (because JavaScript sees a function as an object and we testing for equality between objects is quite a hassle in JavaScript)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When we have a complex function (i.e the computation of that function is costly).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Unrelated, but remember that one scene in justice league where they had to bring Superman back to life? they had a perfect reason to bring him back. The same logic applies here. Introducing useCallback means we're inviting some complexities already into our code, so we should have a perfect reason to useCallback in our code.&lt;/p&gt;

&lt;p&gt;Thank you so much for reading. In the next section, we'll be covering the &lt;code&gt;useReducer&lt;/code&gt; hook. If you have any contributions or comments please drop them in the comment below. Also please follow me for more content like this and stay safe.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Understanding useRef in react</title>
      <dc:creator>Elizabeth</dc:creator>
      <pubDate>Fri, 19 Feb 2021 21:05:06 +0000</pubDate>
      <link>https://dev.to/ilizette/understanding-useref-in-react-e7c</link>
      <guid>https://dev.to/ilizette/understanding-useref-in-react-e7c</guid>
      <description>&lt;p&gt;In my previous post, we talked about useMemo, when we should use it and why we shouldn't overuse it. In this post, we will be looking at the useRef hook and the common use-cases. Let get into it right away.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is the useRef hook
&lt;/h1&gt;

&lt;p&gt;According to the React documentation,&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;useRef returns a mutable ref object whose current property is initialized to the passed argument (initialValue). The returned object will persist for the full lifetime of the component.&lt;br&gt;
In short, useRef is kinda similar to the useState hook, except it returns a mutable object and doesn't cause a component to re-render.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To use the value returned from useRef you need to call the current value. i.e&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ref&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useRef&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Dami&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Dami&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  useRef use cases.
&lt;/h2&gt;

&lt;p&gt;One of the common useCase for useRef is to use it as a reference to a dom element. Every JavaScript DOM element has a &lt;code&gt;ref&lt;/code&gt; attribute and you can use the useRef hook to get access to that element. eg.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./styles.css&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useRef&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setName&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setMessage&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;inputRef&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useRef&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lettersOnly&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/^&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;A-Za-z&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;+$/&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;testLetters&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;lettersOnly&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;setMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Success&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;inputRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;focus&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
      &lt;span class="nf"&gt;setMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Please do not enter a number&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;
        &lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;inputRef&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nx"&gt;placeholder&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Do not enter a number&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
        &lt;span class="nx"&gt;onChange&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;
      &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;testLetters&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Check&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;small&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/small&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the code above we're using the useRef hook to focus on the input field when a user enters a number into the box.&lt;br&gt;
&lt;iframe src="https://codesandbox.io/embed/dazzling-lichterman-l1rlf"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;You'll notice that I am still using useState to hold the value of the content. You would actually want to do this, it is generally a good idea to let react handle your input value in a state instead of using javascript DOM, if not, why else are you using react anyways?&lt;/p&gt;

&lt;p&gt;Another common use case for useRef is to know the number of times a component rerenders. Because the useRef hook actually doesn't cause the component to rerender, you can actually use it to target the number of rerenders.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useRef&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./styles.css&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setNumber&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;rendered&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useRef&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;rendered&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;rendered&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;onChange&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setNumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;I&lt;/span&gt; &lt;span class="nx"&gt;rendered&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;rendered&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;times&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/boring-morning-59y2j"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The useRef hook is one of those hooks that I rarely use but there's more to using useRef.&lt;/p&gt;

&lt;p&gt;I hope this was able to add some clarification to the useRef hook. If you have any questions, comments, or suggestions please send them in the comment below. In my next post, we'll be looking into the &lt;code&gt;useCallback&lt;/code&gt; hook. Meanwhile, stay safe and keep doing amazing things.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
