<?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: ☪️♓🅰️♏⛎🇿🇼Mutezva</title>
    <description>The latest articles on DEV Community by ☪️♓🅰️♏⛎🇿🇼Mutezva (@chamumutezva).</description>
    <link>https://dev.to/chamumutezva</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%2F161844%2Fa19618fe-2ee5-4d66-9581-ab24509185c8.jpg</url>
      <title>DEV Community: ☪️♓🅰️♏⛎🇿🇼Mutezva</title>
      <link>https://dev.to/chamumutezva</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/chamumutezva"/>
    <language>en</language>
    <item>
      <title>ScrolltoTop with React and react-router v6.</title>
      <dc:creator>☪️♓🅰️♏⛎🇿🇼Mutezva</dc:creator>
      <pubDate>Sat, 05 Feb 2022 19:38:00 +0000</pubDate>
      <link>https://dev.to/chamumutezva/scrolltotop-with-react-and-react-router-v6-43j8</link>
      <guid>https://dev.to/chamumutezva/scrolltotop-with-react-and-react-router-v6-43j8</guid>
      <description>&lt;p&gt;&lt;em&gt;Navigating to the top of the page on a multi-page website using React and react-router v6&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I have done a multi-page project with react with navigation in the header and footer. While the navigation on the header is not a real challenge, the footer navigation needs some extra coding for it to work perfectly or at least better.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Footer Navigation - the challenge&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You have been following this website from the top and now you have reached the bottom of the site and at the bottom, there is some navigation to other pages. Clicking on any of the links works, the navigation is moving to the required page. But hold on, I am a keyboard user for one reason or the other. The page has moved to the right page but pressing the tab key again you see that you have been redirected to the bottom of the new page - yes that's a bit frustrating and confusing to assistive technology users.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;The Fix&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create a ScrollToTop function in the App.js file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useEffect } from 'react';
import {  Routes, Route , useLocation } from 'react-router-dom'
import Header from './pages/shared/Header';
import Footer from './pages/shared/Footer';
import Features from './pages/features/Features';
import Pricing from './pages/pricing/Pricing';
import Stories from './pages/stories/Stories';
import Home from './pages/home/Home';
import { DataProvider } from './pages/context/Context';
import './sass/App.scss';

function App() {

  const ScrollToTop = () =&amp;gt; {
    const { pathname } = useLocation();
    console.log(pathname)
    useEffect(() =&amp;gt; {
      window.scrollTo(0, 0);
    }, [pathname]);

    return null;
  }

  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;Header /&amp;gt;

      &amp;lt;DataProvider&amp;gt;

          &amp;lt;ScrollToTop /&amp;gt;
          &amp;lt;Routes&amp;gt;

            &amp;lt;Route path="/" element={&amp;lt;Home /&amp;gt;} /&amp;gt;
            &amp;lt;Route path="stories" element={&amp;lt;Stories /&amp;gt;} /&amp;gt;
            &amp;lt;Route path="features" element={&amp;lt;Features /&amp;gt;} /&amp;gt;
            &amp;lt;Route path="pricing" element={&amp;lt;Pricing /&amp;gt;} /&amp;gt;

          &amp;lt;/Routes&amp;gt;

        &amp;lt;Footer /&amp;gt;
      &amp;lt;/DataProvider&amp;gt;

    &amp;lt;/div&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;p&gt;At this point, if you try the navigation, the focus will still stay at the bottom. I had assumed that I had done everything possible. A few more steps to solve this issue.&lt;/p&gt;

&lt;p&gt;Move to the top of the file that has to be at the top and locate the element that should have focus when the page is navigated to. On this element write a tabindex=-1.&lt;/p&gt;

&lt;p&gt;A negative value (usually tabindex="-1") means that the element is not reachable via sequential keyboard navigation, but could be focused with JavaScript or visually by clicking with the mouse.  A negative value is useful when you have off-screen content that appears on a specific event. The user won't be able to focus any element with a negative &lt;code&gt;tabindex&lt;/code&gt; using the keyboard, but a script can do so by calling the focus() method. (source - MDN)&lt;/p&gt;

&lt;p&gt;import useRef in the same file &lt;br&gt;
import { useContext, useRef , useEffect} from 'react'&lt;/p&gt;

&lt;p&gt;and include the following in the component&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const homeMain = useRef()

    useEffect(() =&amp;gt; {
        homeMain.current.focus()
    })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On the element with the tabindex add the ref attribute &lt;code&gt;&amp;lt;main tabIndex="-1" ref={homeMain} &amp;gt;&lt;/code&gt;. Do this to all the pages .&lt;/p&gt;

&lt;p&gt;Here is a GitHub link to the project &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2eoEfJeO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/ChamuMutezva/photosnap" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2eoEfJeO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/ChamuMutezva/photosnap" alt="Photosnap website - a challenge project by Frontend Mentor" width="" height=""&gt;&lt;/a&gt;. The link for the &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zEMtQZRo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://photosnap-project.netlify.app/" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zEMtQZRo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://photosnap-project.netlify.app/" alt="live preview" width="" height=""&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;For a list of Frontend Mentor challenge projects &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--A9eHLrRn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.frontendmentor.io/challenges" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A9eHLrRn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.frontendmentor.io/challenges" alt="Frontend Mentor Challenge projects" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>[React Number Memory game with Mongodb Realm]</title>
      <dc:creator>☪️♓🅰️♏⛎🇿🇼Mutezva</dc:creator>
      <pubDate>Thu, 13 Jan 2022 17:52:40 +0000</pubDate>
      <link>https://dev.to/chamumutezva/react-number-memory-game-with-mongodb-realm-4ial</link>
      <guid>https://dev.to/chamumutezva/react-number-memory-game-with-mongodb-realm-4ial</guid>
      <description>&lt;h3&gt;
  
  
  Overview of My Submission
&lt;/h3&gt;

&lt;h4&gt;
  
  
  What is the Memory game
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;The memory game is a pairing game that contains a pair of similar objects. In the game i am using a pair of numbers between one and eight.&lt;/li&gt;
&lt;li&gt;The user selects 2 cards one at a time, the idea is to select matching numbers whenever 2 cards are picked. If the cards are similar they remain open otherwise they close after 500ms and the selection process carries on until all cards are matched correctly.&lt;/li&gt;
&lt;li&gt;This particular is a 4 by 4 board game with pairs of numbers between one and eight inclusive.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  MongoDb Atlas and Realm
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;MongoDb atlas and Realm makes it easy to make a simple connection to a backend without hosting your own server and the best news is that these services have a free tier.&lt;/li&gt;
&lt;li&gt;Realm provides the use of functions and has a function editor that assist you to get started. The functions created will be used in the frontend to get the data.&lt;/li&gt;
&lt;li&gt;The database was created using another MongoDB atlas service known as MongoDb Compass.&lt;/li&gt;
&lt;li&gt;here is a sample code of the realm function used in the React Frontend application
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;exports = function(arg){

    let collection = context.services
                    .get("mongodb-atlas") 
                    .db("memoryGame")
                    .collection("memory");

  return collection.find({});
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Submission Category # (Action Star)
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Link to Code
&lt;/h3&gt;

&lt;p&gt;[Github repository] # (&lt;a href="https://github.com/ChamuMutezva/memory-game-2021"&gt;https://github.com/ChamuMutezva/memory-game-2021&lt;/a&gt;)&lt;br&gt;
[Live preview link] # (&lt;a href="https://memory-game-chamu-2021.netlify.app/"&gt;https://memory-game-chamu-2021.netlify.app/&lt;/a&gt;)&lt;/p&gt;
&lt;h3&gt;
  
  
  Additional Resources / Info
&lt;/h3&gt;

&lt;p&gt;[Mongodb Jumpstart videos] # (&lt;a href="https://www.youtube.com/watch?v=RGfFpQF0NpE&amp;amp;list=PL4RCxklHWZ9v2lcat4oEVGQhZg6r4IQGV"&gt;https://www.youtube.com/watch?v=RGfFpQF0NpE&amp;amp;list=PL4RCxklHWZ9v2lcat4oEVGQhZg6r4IQGV&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;[Mongodb University - interactive learning] # (&lt;a href="https://university.mongodb.com/mercury/M001/2021_December_14/chapter/Chapter_1_What_is_MongoDB_/lesson/5f5c03c704e9ff039e32729b/lecture"&gt;https://university.mongodb.com/mercury/M001/2021_December_14/chapter/Chapter_1_What_is_MongoDB_/lesson/5f5c03c704e9ff039e32729b/lecture&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;[Shuffle array] # (&lt;a href="http://stackoverflow.com/a/2450976"&gt;http://stackoverflow.com/a/2450976&lt;/a&gt;)&lt;br&gt;
[Inspiration of code drawn from] # (&lt;a href="https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle"&gt;https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle&lt;/a&gt;)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function shuffle(array) {
    let currentIndex = array.length,
      temporaryValue, randomIndex;

    // While there remain elements to shuffle...
    while (currentIndex !== 0) {

      // Pick a remaining element...
      randomIndex = Math.floor(Math.random() * currentIndex);
      currentIndex -= 1;

      // And swap it with the current element.
      temporaryValue = array[currentIndex];
      array[currentIndex] = array[randomIndex];
      array[randomIndex] = temporaryValue;
    }

    return array;
  };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Screenshots
&lt;/h3&gt;

&lt;p&gt;[Game image 1] # (&lt;a href="https://github.com/ChamuMutezva/memory-game-2021/blob/master/src/assets/start1.png"&gt;https://github.com/ChamuMutezva/memory-game-2021/blob/master/src/assets/start1.png&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;[Game image 2] # (&lt;a href="https://github.com/ChamuMutezva/memory-game-2021/blob/master/src/assets/start2.png"&gt;https://github.com/ChamuMutezva/memory-game-2021/blob/master/src/assets/start2.png&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;[Game image 3] # (&lt;a href="https://github.com/ChamuMutezva/memory-game-2021/blob/master/src/assets/start3.png"&gt;https://github.com/ChamuMutezva/memory-game-2021/blob/master/src/assets/start3.png&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;[Game image 4] # (&lt;a href="https://github.com/ChamuMutezva/memory-game-2021/blob/master/src/assets/endgame.png"&gt;https://github.com/ChamuMutezva/memory-game-2021/blob/master/src/assets/endgame.png&lt;/a&gt;)&lt;/p&gt;

</description>
      <category>atlashackathon</category>
      <category>mongodb</category>
    </item>
  </channel>
</rss>
