<?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>Forem: Niharika Khanna</title>
    <description>The latest articles on Forem by Niharika Khanna (@niharikak101).</description>
    <link>https://forem.com/niharikak101</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%2F9023%2F16074636.jpeg</url>
      <title>Forem: Niharika Khanna</title>
      <link>https://forem.com/niharikak101</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/niharikak101"/>
    <language>en</language>
    <item>
      <title>Integrating MapBox with Next.js — the Cheaper Alternative to Google Maps</title>
      <dc:creator>Niharika Khanna</dc:creator>
      <pubDate>Sat, 05 Dec 2020 08:18:49 +0000</pubDate>
      <link>https://forem.com/niharikak101/integrating-mapbox-with-next-js-the-cheaper-alternative-to-google-maps-g39</link>
      <guid>https://forem.com/niharikak101/integrating-mapbox-with-next-js-the-cheaper-alternative-to-google-maps-g39</guid>
      <description>&lt;p&gt;Lately, I’ve been working on creating an &lt;a href="//sustaynably.com"&gt;online platform for eco hotels and resorts&lt;/a&gt;, and found myself needing to render a map with some clickable marker pins (which we are going to reproduce in this tutorial). After scouring the internet with possible solutions, two immediate options sprung up — Google Maps and MapBox. While most of us are familiar with Google Maps because of the overwhelming presence it has in all our lives, integrating it in an application, I found, is less than ideal. Building a bootstrapped project, I wanted to keep the costs at a minimum and Google Map’s &lt;a href="https://cloud.google.com/maps-platform/pricing" rel="noopener noreferrer"&gt;pricing structure&lt;/a&gt; would mean that the costs would begin to add up.&lt;/p&gt;

&lt;h2&gt;
  
  
  Enter MapBox!
&lt;/h2&gt;

&lt;p&gt;With a competitive &lt;a href="https://www.mapbox.com/pricing/" rel="noopener noreferrer"&gt;pricing structure&lt;/a&gt; (the first 50,000 requests on web are free) and an easy-to-use and well documented API, MapBox is a good alternative to Google Maps. It is also built on top of &lt;a href="https://www.openstreetmap.org/" rel="noopener noreferrer"&gt;OpenStreetMap&lt;/a&gt;, which is an open source mapping project. Win, win!&lt;/p&gt;

&lt;h2&gt;
  
  
  What are we building?
&lt;/h2&gt;

&lt;p&gt;We’re going to be querying MapBox’s search api to get some locations of an infamous coffee shop called Greggs, focusing our search on the Greater London region. Then, we are going to render these places in our MapBox &lt;code&gt;&amp;lt;Map&amp;gt;&lt;/code&gt; component with a bunch of clickable markers. On click, these markers will display some dismissible popups.&lt;/p&gt;

&lt;p&gt;The finished product will look something like,&lt;br&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%2Fi%2F8ihpmagd55bqx9jmevyw.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%2Fi%2F8ihpmagd55bqx9jmevyw.png" alt="map" width="800" height="473"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Let's Code!
&lt;/h1&gt;
&lt;h2&gt;
  
  
  Make a MapBox account to get your access token
&lt;/h2&gt;

&lt;p&gt;The first thing you will need to do is to make a MapBox account so that you can get an access token. We will use this token to make requests to the various MapBox APIs.&lt;br&gt;
Once you have your access token, it is time to set up your very own Next.js project and integrate all the juicy functionality that MapBox provides.&lt;/p&gt;
&lt;h2&gt;
  
  
  Setup a new Next.js project (Skip this if you already have a project of your own)
&lt;/h2&gt;

&lt;p&gt;Setting up a Next.js project is straightforward, you can either follow the instructions laid out in the &lt;a href="https://nextjs.org/learn/basics/create-nextjs-app" rel="noopener noreferrer"&gt;official documentation&lt;/a&gt; or run the following command to set up a new Next.js project (Make sure you have Node.js installed).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-next-app mapbox-project
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, &lt;code&gt;cd&lt;/code&gt; into the &lt;code&gt;mapbox-project&lt;/code&gt; directory and run the development server by running &lt;code&gt;npm run dev&lt;/code&gt; or &lt;code&gt;yarn dev&lt;/code&gt; . Et Voila! Your Next.js project is up and running!&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup A MapBox Map
&lt;/h2&gt;

&lt;p&gt;Next up, it’s time to render a MapBox map in our project. We do this by adding a &lt;a href="https://github.com/visgl/react-map-gl" rel="noopener noreferrer"&gt;MapBox library&lt;/a&gt; written by the team at Uber called react-map-gl. This contains a suite of React components for MapBox. Add this library to your project by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add react-mapbox-gl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this, we’re going to create a Map component which will live in &lt;code&gt;components/Map.js&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Create your Map.js file and add the following code to it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from "react";
import ReactMapGL from "react-map-gl";
export default function Map() {
  const [viewport, setViewport] = useState({
  width: "100%",
  height: "100%",
  // The latitude and longitude of the center of London
  latitude: 51.5074,
  longitude: -0.1278,
  zoom: 10
});
return &amp;lt;ReactMapGL
  mapStyle="mapbox://styles/mapbox/streets-v11"
  mapboxApiAccessToken={process.env.MAPBOX_KEY}
  {...viewport}
  onViewportChange={(nextViewport) =&amp;gt; setViewport(nextViewport)}
  &amp;gt;
&amp;lt;/ReactMapGL&amp;gt;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is not going to work just yet. One of the biggest features of Next.js is the server side rendering it offers. MapBox, however, requires the global window object in order to work correctly. If you are server side rendering your app, you will need to dynamically import it into your page. This means that instead of importing it like a regular component,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Map from '../components/Map'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will have to import it dynamically. We will do this by using Next.js &lt;code&gt;dynamic imports&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In your &lt;code&gt;pages/index.js&lt;/code&gt; file (or wherever you’re rendering your Map component) add the following code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Map = dynamic(() =&amp;gt; import("../components/Map"), {
  loading: () =&amp;gt; "Loading...",
  ssr: false
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This means that our MapBox component will now selectively be rendered client side. Perfect!&lt;/p&gt;

&lt;p&gt;The only thing we need to do now is to add MapBox’s CSS files to our project. The easiest way to do this is to modify your existing &lt;code&gt;_app.js&lt;/code&gt; or by adding a custom &lt;code&gt;_document.js&lt;/code&gt; file. Then add a link to the CSS to the &lt;code&gt;&amp;lt;Head&amp;gt;&lt;/code&gt; in your render function. You can get the latest version of the CSS files in their &lt;a href="https://docs.mapbox.com/mapbox-gl-js/api/" rel="noopener noreferrer"&gt;API documentation&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;&amp;lt;head&amp;gt;
&amp;lt;link href='https://api.mapbox.com/mapbox-gl-js/v1.12.0/mapbox-gl.css' rel='stylesheet' /&amp;gt;
&amp;lt;/head&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Perfect. Your Map should now be up and running! Let’s take this a step further and try rendering some clickable pins on our map.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use MapBox’s search API to fetch a list of landmarks
&lt;/h2&gt;

&lt;p&gt;MapBox has a really handy geocoding API which you can be used to fetch a list of locations, with their latitudes and longitudes. We’re going to be fetching a list of Greggs (a take-away fast food and coffee shop) in London and render them as pins on our Map.&lt;br&gt;
First, let’s query our list by adding a simple fetch call to the Mapbox geocoding API. We want to search within the geographic bounds of London and want to cap our search at 10 results (London is huge and Londoner’s love their Gregg’s vegan sausage rolls. We don’t want to overwhelm ourselves with all the possibilities!). MapBox’s Geocoding Place Search API takes the following parameters, with some additional query strings.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/geocoding/v5/mapbox.places/{search_text}.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will be using the limit query parameter to cap our results at 10, and the bbox parameter to specify the latitudinal and longitudinal bounds of London.&lt;br&gt;
With all this in mind, our search url will look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://api.mapbox.com/geocoding/v5/mapbox.places/greggs.json?access_token=${process.env.MAPBOX_KEY}&amp;amp;bbox=-0.227654%2C51.464102%2C0.060737%2C51.553421&amp;amp;limit=10

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

&lt;/div&gt;



&lt;p&gt;We can use this url, to make a simple fetch call in our page. Our modified page will now look 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;const Map = dynamic(() =&amp;gt; import("../components/Map"), {
  loading: () =&amp;gt; "Loading...",
  ssr: false
});
const url = `https://api.mapbox.com/geocoding/v5/mapbox.places/greggs.json?access_token=${process.env.MAPBOX_KEY}&amp;amp;bbox=-0.227654%2C51.464102%2C0.060737%2C51.553421&amp;amp;limit=10`;
export default function IndexPage() {
  const [locations, setLocations] = useState([]);
  useEffect(() =&amp;gt; {
    const fetchLocations = async () =&amp;gt; {
      await fetch(url).then((response) =&amp;gt;
        response.text()).then((res) =&amp;gt; JSON.parse(res))
      .then((json) =&amp;gt; {
        setLocations(json.features);
      }).catch((err) =&amp;gt; console.log({ err }));
    };
    fetchLocations();
  }, []);
  return (&amp;lt;Container&amp;gt;
    &amp;lt;Map /&amp;gt;
  &amp;lt;/Container&amp;gt;);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We now have a list of 10 Greggs locations!&lt;/p&gt;

&lt;h2&gt;
  
  
  Using our search results to render pins on our map
&lt;/h2&gt;

&lt;p&gt;Now that we have a list of places, we can render these on a Map. &lt;code&gt;react-map-gl&lt;/code&gt; comes with a handy &lt;code&gt;&amp;lt;Marker&amp;gt;&lt;/code&gt; component that makes our task pretty straight forward. First we need to pass these locations to our &lt;code&gt;&amp;lt;Map&amp;gt;&lt;/code&gt; component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return (&amp;lt;Container&amp;gt;
    &amp;lt;Map locations={locations} /&amp;gt;
  &amp;lt;/Container&amp;gt;);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, within out Map component, we need to render a pin for each of these locations by passing their latitude and longitude to the &lt;code&gt;&amp;lt;Marker&amp;gt;&lt;/code&gt; component.&lt;/p&gt;

&lt;p&gt;Our final Map component will look 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;import { useState } from "react";
import ReactMapGL, { Marker } from "react-map-gl";
export default function Map({ locations }) {
  const [viewport, setViewport] = useState({
    width: "100%",
    height: "100%",
    // The latitude and longitude of the center of London
    latitude: 51.5074,
    longitude: -0.1278,
    zoom: 10
  });
return &amp;lt;ReactMapGL
  mapStyle="mapbox://styles/mapbox/streets-v11"
  mapboxApiAccessToken={process.env.MAPBOX_KEY}
  {...viewport}
  onViewportChange={(nextViewport) =&amp;gt; setViewport(nextViewport)}
  &amp;gt;
  {locations.map((location) =&amp;gt; (
    &amp;lt;div key={location.id}&amp;gt;
      &amp;lt;Marker
      latitude={location.center[1]}
      longitude={location.center[0]}
      offsetLeft={-20}
      offsetTop={-10}&amp;gt;
        &amp;lt;span role="img" aria-label="push-pin"&amp;gt;📌&amp;lt;/span&amp;gt;
      &amp;lt;/Marker&amp;gt;
    &amp;lt;/div&amp;gt;
  ))}
&amp;lt;/ReactMapGL&amp;gt;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Making the pins clickable
&lt;/h2&gt;

&lt;p&gt;We’re almost there! The last thing we want to do to make these maps fully functioning and interactive, is to add a popup with the name of the place. Again, Mapbox comes with a handy Popup component that makes this easy to do. We will simply add an onClick handler to our pins which will capture the details of the selected location, then we will pass the latitude and the longitude of the selected location to our &lt;code&gt;&amp;lt;Popup&amp;gt;&lt;/code&gt; component. It’ll all be clear in a second!&lt;br&gt;
Within the Map component, add a &lt;code&gt;useState&lt;/code&gt; hook to capture the selected location.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default function Map({ locations }) {
  // UseState hook
  const [selectedLocation, setSelectedLocation] = useState({})
  const [viewport, setViewport] = useState({
    width: "100%",
    height: "100%",
    // The latitude and longitude of the center of London
    latitude: 51.5074,
    longitude: -0.1278,
    zoom: 10
  });
......
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will also modify the render block to add an onClick handler and the &lt;code&gt;&amp;lt;Popup&amp;gt;&lt;/code&gt; component that we just mentioned.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;......
return &amp;lt;ReactMapGL
  mapStyle="mapbox://styles/mapbox/streets-v11"
  mapboxApiAccessToken={process.env.MAPBOX_KEY}
  {...viewport}
  onViewportChange={(nextViewport) =&amp;gt; setViewport(nextViewport)}
  &amp;gt;
  {locations.map((location) =&amp;gt; (
    &amp;lt;div key={location.id}&amp;gt;
      &amp;lt;Marker
      latitude={location.center[1]}
      longitude={location.center[0]}
      offsetLeft={-20}
      offsetTop={-10}&amp;gt;
        &amp;lt;a onClick={() =&amp;gt; {
          setSelectedLocation(location);
        }}&amp;gt;
          &amp;lt;span role="img" aria-label="push-pin"&amp;gt;📌&amp;lt;/span&amp;gt;
        &amp;lt;/a&amp;gt;
      &amp;lt;/Marker&amp;gt;
      {selectLocation.id === location.id ? (
      &amp;lt;Popup
      onClose={() =&amp;gt; setSelectedLocation({})}
      closeOnClick={true}
      latitude={location.center[1]}
      longitude={location.center[0]}&amp;gt;
        {location.place_name}
      &amp;lt;/Popup&amp;gt;) : (false)}
    &amp;lt;/div&amp;gt;
  ))}
&amp;lt;/ReactMapGL&amp;gt;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;&amp;lt;Popup&amp;gt;&lt;/code&gt; component takes an onClose handler which sets the selectedLocation to {}.&lt;/p&gt;

&lt;p&gt;And that is all! We’ve managed to render a map, rendered some pins on our map and managed to make them clickable with popups! Here’s our final result:&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%2Fi%2Flk5uzokv8h1bm1s7x79j.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%2Fi%2Flk5uzokv8h1bm1s7x79j.png" alt="map" width="800" height="473"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>mapbox</category>
      <category>nextjs</category>
      <category>react</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Name, Place, Animal, Thing — Revisiting a childhood game and bringing it online with React and WebSockets</title>
      <dc:creator>Niharika Khanna</dc:creator>
      <pubDate>Fri, 15 May 2020 16:35:40 +0000</pubDate>
      <link>https://forem.com/niharikak101/name-place-animal-thing-revisiting-a-childhood-game-and-bringing-it-online-with-react-and-websockets-45mb</link>
      <guid>https://forem.com/niharikak101/name-place-animal-thing-revisiting-a-childhood-game-and-bringing-it-online-with-react-and-websockets-45mb</guid>
      <description>&lt;p&gt;TL; DR: I made a game, play now: &lt;a href="//nameplaceanimalthing.online"&gt;Name, Place, Animal, Thing&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mRmfAnW_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/sx0y7pxxjkmtu81cqamf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mRmfAnW_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/sx0y7pxxjkmtu81cqamf.png" alt="Name, Place, Animal, Thing banner"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are two things I’ve done quite a bit in this time of social isolation — catch up with old friends and play a ridiculous amount of Skribbl.io and Ludo King with said old friends.&lt;/p&gt;

&lt;p&gt;During one of these late night catch-ups, someone suggested that we play “Name, Place, Animal, Thing” — a multiplayer game we used to play in our middle school notebooks. For those unfamiliar with the rules, here’s a watered down version — the game lasts over multiple rounds, and at the beginning of each round, you get an alphabet. You then have 60 seconds to think of a “Name”, a “Place”, an “Animal” and a “Thing” — and note down words for each of those categories, but only words that begin with that letter. The person who gets the most correct answers over the course of the game wins. Easy enough!&lt;/p&gt;

&lt;p&gt;Except, I couldn’t find an online version! Now what do we do? Wouldn’t not building my own online version of the game be an insult to my craft?&lt;/p&gt;

&lt;h1&gt;
  
  
  But what does making a game even entail?
&lt;/h1&gt;

&lt;p&gt;I have no idea. Game design? UI design? Icons? Graphics? Avatars? Writing the actual code? Let’s organise our thoughts a little bit.&lt;/p&gt;

&lt;h1&gt;
  
  
  Defining Requirements
&lt;/h1&gt;

&lt;p&gt;The first thing I needed to do was define gameplay and outline a set of bare minimum requirements for the game to be playable. Let’s break it down.&lt;/p&gt;

&lt;h2&gt;
  
  
  Game Setup
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The game has to be multiplayer and sync between people real-time across different geographies (Hello, sockets!)&lt;/li&gt;
&lt;li&gt;For starters, I only want the game to be playable in small private game rooms.&lt;/li&gt;
&lt;li&gt;A player (the admin) would be able to create a new game room, which would generate the game code that could be shared with up to 10 people who will be able to join the game and play against each other&lt;/li&gt;
&lt;li&gt;The admin would be able to define the number of rounds per game and the additional categories (besides name, place, animal and thing) in each game&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Game Play
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;At the beginning of each round, a random alphabet needs to be selected — Once an alphabet is picked, it cannot be picked again&lt;/li&gt;
&lt;li&gt;The rounds need to be timed at 60 seconds, but the timer stops as soon as the first person submits their response&lt;/li&gt;
&lt;li&gt;Once all responses (or really, the first response) is submitted, we move to scoring&lt;/li&gt;
&lt;li&gt;For starters, the game would be self scored — players are able to give themselves either 0, 5 or 10 points. 10 for every correct answer, and 5 for every answer they share with someone (I went back and forth on this. I think there is value in people scoring each other instead of themselves, but I didn’t want to add that complexity just yet — I also toyed with the idea of automatic scoring, but again — too much complexity for version 1)&lt;/li&gt;
&lt;li&gt;Once all scores were collated, each player would be able to see everyone else’s score and then start the next round (I think having the ability to reject someone’s inputted score could be a possible update for future versions, but we’re keeping it simple)&lt;/li&gt;
&lt;li&gt;and repeat! Once all the rounds are over, the game ends and the person with the highest score wins the game&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Designs
&lt;/h1&gt;

&lt;p&gt;Now, I am most definitely not a designer, but I wanted the game UI to have a notebook-y feel. I also am not a fan of (but mostly don’t know how to design) big and complex UIs. Let’s take the minimalistic approach (can you sense a pattern?):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I wanted the game to look careless — like it was handwritten on a sheet of paper&lt;/li&gt;
&lt;li&gt;Fonts are important! I searched long and hard(ish) on Google Fonts, and went with Schoolbell. Since the game UI is not very complex, the font really would have to take centre stage&lt;/li&gt;
&lt;li&gt;Time for some icons and graphics; I found some hand-drawn icon packs on FlatIcon that I could use for buttons and user avatars
Et voila!&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Tech Stack
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Real-Time Communication with WebSockets
&lt;/h2&gt;

&lt;p&gt;I am primarily a front-end engineer (with some back-end exposure), but this mini project would require a server that would enable players (we’re going to call each player a ‘socket’) to real-time communicate with each other. I was aware of the WebSockets protocol as a bi-directional communication solution, but had never implemented my own. I decided to go with Socket.io, a library that uses the WebSockets protocol to enable communication between the browser and the server, and also adds some additional features (like fallbacks, automatic reconnects and broadcasting to multiple “sockets”).&lt;br&gt;
JavaScript always has been my language of choice and I didn’t want to make the learning curve steeper than it already was. The back-end would be a Node.js server using socket.io.&lt;br&gt;
The internet has a plethora of resources written by competent backend engineers, so I will not go into the details of Node.js, WebSockets and Socket.io.&lt;/p&gt;

&lt;h2&gt;
  
  
  Front-End Implementation
&lt;/h2&gt;

&lt;p&gt;I used create-react-app to bootstrap the project, but once I was done with the basic functionality, moved it over to Next.js because of the supposed improved SEO performance (my game did start indexing higher on google after this, but this was not a controlled experiment so I can’t really say).&lt;/p&gt;

&lt;p&gt;I’ve also become a big fan of styled components, and having my CSS scoped to single components has really improved the developer experience for me. I don’t think I will be going back to the world of chaotic stylesheets anytime soon.&lt;br&gt;
A couple of weeks in, and I managed to actually produce a playable v1 which I have been testing with friends and co-workers. Testing with actual people instead of repeatedly playing the game against myself has been a very insightful experience — I could write an entire post on that in itself — and I’ve got some really thoughtful, constructive and actionable feedback that I would like to take into future versions of the game, but for now, the first version is online and playable &lt;a href="//nameplaceanimalthing.online"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Thoughts and feedback are always welcome and appreciated. Happy playing!&lt;/p&gt;

</description>
      <category>react</category>
      <category>node</category>
      <category>socketio</category>
      <category>html</category>
    </item>
    <item>
      <title>Hi, I'm Niharika Khanna</title>
      <dc:creator>Niharika Khanna</dc:creator>
      <pubDate>Tue, 07 Mar 2017 13:07:48 +0000</pubDate>
      <link>https://forem.com/niharikak101/hi-im-niharika-khanna</link>
      <guid>https://forem.com/niharikak101/hi-im-niharika-khanna</guid>
      <description>&lt;p&gt;I have been coding for 2 years.&lt;/p&gt;

&lt;p&gt;You can find me on GitHub as &lt;a href="https://github.com/niharikak101" rel="noopener noreferrer"&gt;niharikak101&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I live in London.&lt;/p&gt;

&lt;p&gt;I study at UCL.&lt;/p&gt;

&lt;p&gt;I mostly program in these languages: Javascript.&lt;/p&gt;

&lt;p&gt;I am currently learning more about FOSS.&lt;/p&gt;

&lt;p&gt;Nice to meet you.&lt;/p&gt;

</description>
      <category>introduction</category>
    </item>
  </channel>
</rss>
