<?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: Shadman Shakib</title>
    <description>The latest articles on DEV Community by Shadman Shakib (@shadmanshakib).</description>
    <link>https://dev.to/shadmanshakib</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%2F573206%2F7f0471ac-ec09-4da6-a0a6-53d01f03cb4c.jpg</url>
      <title>DEV Community: Shadman Shakib</title>
      <link>https://dev.to/shadmanshakib</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shadmanshakib"/>
    <language>en</language>
    <item>
      <title>Getting products from Shopify Storefront API</title>
      <dc:creator>Shadman Shakib</dc:creator>
      <pubDate>Wed, 30 Mar 2022 00:41:18 +0000</pubDate>
      <link>https://dev.to/shadmanshakib/getting-products-from-shopify-storefront-api-3d8p</link>
      <guid>https://dev.to/shadmanshakib/getting-products-from-shopify-storefront-api-3d8p</guid>
      <description>&lt;h3&gt;
  
  
  Set up a Next.js project
&lt;/h3&gt;

&lt;p&gt;First of all let’s set up a next JS project. We can get started with the following command. I have used Typescript for my project but you can use JavaScript if you want.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn create next-app --typescript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also install Mantine component library for styling and Apollo for data fetching.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn @mantine/core @mantine/hooks @appllo-graphql graphql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the &lt;code&gt;_app.tsx&lt;/code&gt; file import provider from both &lt;code&gt;@appllo/client&lt;/code&gt; and &lt;code&gt;@mantine/core&lt;/code&gt; . Then wrap the whole app with the providers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//_app.tsx
import { MantineProvider } from "@mantine/core";
import { ApolloProvider } from "@apollo/client";
import "../styles/globals.css";
import Client from "../services/Apollo";
import type { AppProps } from "next/app";

function MyApp({ Component, pageProps }: AppProps) {
  return (
    &amp;lt;ApolloProvider client={Client}&amp;gt;
      &amp;lt;MantineProvider&amp;gt;
        &amp;lt;Component {...pageProps} /&amp;gt;
      &amp;lt;/MantineProvider&amp;gt;
    &amp;lt;/ApolloProvider&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;ApplloProvider&lt;/code&gt; will receive a client prop. Need provider the credential on &lt;code&gt;Client.ts&lt;/code&gt; file. This file will content API endpoint and API key which we get from Storefront dashboard. &lt;/p&gt;

&lt;h3&gt;
  
  
  Setting up the environment variable
&lt;/h3&gt;

&lt;p&gt;I have placed my initial store name and API key in the .env file as a environment variable. The API key we need to get it from Shopify dashboard. To get an API key we need to add a private app to our Shopify store.&lt;/p&gt;

&lt;p&gt;Storefront API provides all the functionalities of a Shopify store. To get access to Storefront API we need a API key. We need to create a private app to get the API key. First, go to Dashboard, go to Apps section, here you will find a option of creating a private app. Just create a Private app and get your API key.&lt;/p&gt;

&lt;h3&gt;
  
  
  Function to get products
&lt;/h3&gt;

&lt;p&gt;Now lets setup the a &lt;code&gt;getProducts()&lt;/code&gt; function which will get products form the backend.&lt;/p&gt;

&lt;p&gt;For this step you must have product in your store. Now you can query for products from the Shopify API. For simplicity and code readability we will name the function &lt;code&gt;getProducts()&lt;/code&gt; . We fill get first 5 products from our store. &lt;/p&gt;

&lt;p&gt;For Static rendering  of data call the API inside the &lt;code&gt;getStaticProps()&lt;/code&gt; function. Use &lt;code&gt;getStaticProps&lt;/code&gt; get products from that store.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Client from "@services/Apollo";
import { gql } from "@apollo/client";

export default async function getProducts() {
  const { data, error, loading } = await Client.query({
    query: gql`
      query Products {
        products(first: 5) {
          edges {
            node {
              id
              handle
              title
              description
              variants(first: 10) {
                edges {
                  node {
                    id
                    image {
                      height
                      url
                      altText
                      width
                    }
                  }
                }
              }
            }
          }
        }
      }
    `,
  });
  return { data, error, loading };
}


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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Showing product list on UI
&lt;/h3&gt;

&lt;p&gt;Now map the products array. We need to go through edges and node in the Storefront API in order get the actual data&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  _.map(data.products.edges, (product: Product) =&amp;gt; {
              const { id, title, description, variants } = product.node;
              const url = variants.edges[0].node.image.url;
              return (
                &amp;lt;Card key={id}&amp;gt;
                  &amp;lt;h3&amp;gt;{title}&amp;lt;/h3&amp;gt;
                  &amp;lt;img alt={title} src={url} /&amp;gt;
                  &amp;lt;p&amp;gt;{description}&amp;lt;/p&amp;gt;
                  &amp;lt;Button&amp;gt;Add to cart&amp;lt;/Button&amp;gt;
                &amp;lt;/Card&amp;gt;
              );
            })}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;More information on:&lt;br&gt;
&lt;a href="https://shopify.dev/api/storefront"&gt;https://shopify.dev/api/storefront&lt;/a&gt;&lt;br&gt;
&lt;a href="https://nextjs.org"&gt;https://nextjs.org&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How I use Context and Hooks to manage State in React JS</title>
      <dc:creator>Shadman Shakib</dc:creator>
      <pubDate>Mon, 10 Jan 2022 16:50:07 +0000</pubDate>
      <link>https://dev.to/shadmanshakib/how-i-use-context-and-hooks-to-manage-state-in-react-js-jm0</link>
      <guid>https://dev.to/shadmanshakib/how-i-use-context-and-hooks-to-manage-state-in-react-js-jm0</guid>
      <description>&lt;p&gt;Managing state is a big part of front-end development in this age of JavaScript frameworks. There are a lot of options to manage state in React JS. May be most common using Redux. But using Redux for a small application may not be ideal. React has a built-in context API and hooks to manage state. In this article I will try to explain how I manage state with Context API and hooks.&lt;/p&gt;

&lt;h3&gt;
  
  
  Context Overview
&lt;/h3&gt;

&lt;p&gt;According to official React documentation, Context provides a way to share values between components without having to explicitly pass a prop through the level of the tree. Basically, what Context does is make state available anywhere from the application without passing it through props.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating Context
&lt;/h3&gt;

&lt;p&gt;You can create context simply by calling &lt;em&gt;createContext()&lt;/em&gt; .&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const UIContext=React.createContext(initialState)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates a context object. When React renders a component that subscribes to this Context object it will read the current context value form the closest matching Provider above it in the tree. The initial state is only used when a component dose not have a matching Provider above it in the tree. For example passing the toggle menu state as initial state.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from "react"
//setting up the initial state
const initialState={
isMenuOpen:false;
}
//creating a context
const UIContext=React.createContext(initialState)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Setting up the Provider function
&lt;/h3&gt;

&lt;p&gt;Every context object comes with a Provider component that allows consuming components to subscribe to context changes. In order to get access to the state one component must be placed inside the provider. I have created a Provider function to accomplish this task.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const UIProvider=(props)=&amp;gt;{
return &amp;lt;UIContext.Provider value={} {...props}/&amp;gt;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Using Hooks to change the state
&lt;/h3&gt;

&lt;p&gt;Hooks are functions that let you “hook into” React state and life cycle features from functional components. Before introductions of hooks in React 16.8 class-based components were mandatory for any projects that require states, life-cycle methods, and many other important functionalities.&lt;br&gt;
The &lt;code&gt;useReducer&lt;/code&gt; hook is used to handle complex logic. The hook takes a reducer as an argument and can optionally take the initial state and an &lt;code&gt;init&lt;/code&gt; function as arguments. The &lt;code&gt;useReducer&lt;/code&gt; It’s return states and a function which you can call to dispatch action. Writing Reducer functions for your context&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [state, dispatch]=React.useReducer(reducer, initialState ,init)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Dispatching action to change state
&lt;/h3&gt;

&lt;p&gt;We can dispatch functions by calling the dispatch function we get from the useReducer hook. Here we specify the type of action we wanna dispatch.&lt;br&gt;
The useCallback hook will return a memorized version of the callback that only changes if one of the dependencies has changed. This is used to prevent unnecessary renders.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//useReducer Hook
const [state,dispatch]=React.useReducer(uiReducer,initialState)
//dispatching action
const toggleMenu=React.useCallback(()=&amp;gt;dispatch({type:"TOGGLE_MENU"}),[dispatch])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Passing the value to Context Provider
&lt;/h3&gt;

&lt;p&gt;Now we need to pass our state and actions in the UIContext provider. Here, I have used the useMemo hook to memorize the value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from "react"

export const UIProvider=(props)=&amp;gt;{
const [state,dispatch]=React.useReducer(uiReducer,initialState)
//dispatching action
const toggleMenu=React.useCallback(()=&amp;gt;dispatch({type:"TOGGLE_MENU"}),[dispatch])

const value=useMemo(()=&amp;gt;({...state,}),[state])
return &amp;lt;UIContext.Provider value={value} {...props}/&amp;gt;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Putting the App inside provider function
&lt;/h3&gt;

&lt;p&gt;This will make the state available to all the components of the app. For this we need to pass the entire app component inside the &lt;code&gt;UIProvider&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//index.js
import {UIProvider} from "./UIContext"
export default function Index (){
return (
&amp;lt;UIProvider&amp;gt;
    &amp;lt;App/&amp;gt;
&amp;lt;/UIProvider&amp;gt;
  )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Building a custom hook to consume the context
&lt;/h3&gt;

&lt;p&gt;Most of the time I create a custom hook to consume context.&lt;br&gt;
HereuseContext hook is used to consume Context. We need to pass the name of the Context which we wanna use in order to consume the context.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//useUI.tsx
import React from "react"
import UIContext from "./UIContext"
const useUI=()=&amp;gt;{
const context=React.useContext(UIContext)
return context;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Using useUI hook
&lt;/h3&gt;

&lt;p&gt;Now it’s time to use the useUI hook. Simply, import it and call it inside the functional component you want to use. Here we will get the value &lt;code&gt;isMenuOpen&lt;/code&gt; and &lt;code&gt;toggleMenu&lt;/code&gt; function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import useUI from "./hooks/useUI"
const {isMenuOpen, toggleMenu}=useUI()
export const App=()=&amp;gt;{
return (
&amp;lt;div&amp;gt;
&amp;lt;button onClick={toggleMenu}&amp;gt;Click &amp;lt;/button&amp;gt;
&amp;lt;p&amp;gt;{isMenuOpen? "Open" : "Close"} &amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt;
)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thank you for reading the article. If I can help you some way let me know. I will do my best. &lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>reactnative</category>
      <category>redux</category>
    </item>
    <item>
      <title>Building a NFT marketplace frontend (Typescript + Next JS + Tailwind CSS)</title>
      <dc:creator>Shadman Shakib</dc:creator>
      <pubDate>Sun, 02 Jan 2022 14:16:06 +0000</pubDate>
      <link>https://dev.to/shadmanshakib/building-a-nft-maketplace-frontend-typescript-next-js-tailwind-css-3g28</link>
      <guid>https://dev.to/shadmanshakib/building-a-nft-maketplace-frontend-typescript-next-js-tailwind-css-3g28</guid>
      <description>&lt;p&gt;Warning: I don’t want to waste you time here is nothing very important. It’s just few of my thoughts what I’m using to build a NFT market place theme. &lt;/p&gt;

&lt;p&gt;For a long time really wanted to build something with Next JS. But didn’t really get the time or patience to build it. First thought I would build a e-commerce website and Shopify API with it. As  WEB 3.0 and NFT’s is taking over the internet I thought why not build a NFT marketplace. Design mainly taken from opensea. I’m using Typescript instead of using JavaScript. And for styling I’m using Tailwind CSS. &lt;/p&gt;

&lt;h2&gt;
  
  
  Typescript
&lt;/h2&gt;

&lt;p&gt;TypeScript is &lt;strong&gt;a superset of the JavaScript language&lt;/strong&gt; that has a single open-source compiler and is developed mainly by a single vendor: Microsoft. The goal of TypeScript is to help catch mistakes early through a type system and to make JavaScript development more efficient. &lt;/p&gt;

&lt;p&gt;Actually, speaking truth I have never used JavaScript that much. After reading some article and watching YouTube video it was clear to me Typescript is a better option. &lt;/p&gt;

&lt;h2&gt;
  
  
  React JS
&lt;/h2&gt;

&lt;p&gt;React is best for building complex UI. Where every single day there is development of JavaScript framework or library, React is by far the most used JavaScript library/framework to build UI. React component principle is great to write clean code and maintaining your code base. &lt;/p&gt;

&lt;h2&gt;
  
  
  Next JS 12
&lt;/h2&gt;

&lt;p&gt;Next JS is a JavaScript framework build on the top of React which is really great to build complete website. React is mostly used to build Single page application(SPA) which not that great for SEO. In next js you have option for server side rendering(SSR) or Static Generation (SSG) which is great for SEO. Also it’s much easier to build website like this with Next Js as it has many of things like routing, image processing build in. &lt;/p&gt;

&lt;h2&gt;
  
  
  Tailwind CSS 3
&lt;/h2&gt;

&lt;p&gt;Tailwind CSS basically is a CSS framework. It is base on utility principle. You need to add some class names in your html tags for styling. Tailwind really makes life really easy.  It’s really easy to make responsive design with it. Tailwind prioritize mobile first designing. Where you first write code for mobile screen.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Why cloning can help you become a better Programmer</title>
      <dc:creator>Shadman Shakib</dc:creator>
      <pubDate>Mon, 20 Sep 2021 13:54:37 +0000</pubDate>
      <link>https://dev.to/shadmanshakib/why-cloning-can-help-you-become-a-better-programmer-143c</link>
      <guid>https://dev.to/shadmanshakib/why-cloning-can-help-you-become-a-better-programmer-143c</guid>
      <description>&lt;p&gt;If you are a self taught developer like me may face the challenge of not going beyond the basic level of programming. Watching YouTube tutorials and courses are good for understanding the basics which are really important in the beginning. But once you pass the basic level YouTube tutorials and courses are not that much helpful. &lt;/p&gt;

&lt;p&gt;Now every developer has two options from here: either become a mediocre developer or become a pro. The only way to become a pro is by practicing real world problems. If you wanna build something of your own that’s great. But it’s not easy to come out with an idea and implement that idea. You need to learn a lot more than just coding to be able to build something that looks great. Here I believe cloning is the best strategy. &lt;/p&gt;

&lt;p&gt;What you need to get a job is showing your work to the employer. By cloning you not only improve your development skill but also create projects that you can show to the employer. These projects also have real life use cases with beautiful UI. Building these definitely help you to become a better programmer.&lt;/p&gt;

&lt;p&gt;There are some important things to remember when you are cloning though. Your clone may not work perfectly or look perfect and that’s fine. Just try to get as close as possible. Don’t try to make one pixel perfect design, rather try to build as many apps as possible. The more you try the better you get. Another important thing you can do is document your journey and share it on social media. It will help you build connections and meet with great people online. Let others know what you're doing and what kinds of problems you are facing. This will open many opportunities to you. &lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
