<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Javascript on David Lang</title>
    <link>https://www.davidlang.tech/tags/javascript/</link>
    <description>Recent content in Javascript on David Lang</description>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate>Sun, 28 May 2023 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://www.davidlang.tech/tags/javascript/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Store additional user information in firebase using react and javascript</title>
      <link>https://www.davidlang.tech/posts/store-additional-user-information-in-firebase-using-react-and-javascript/</link>
      <pubDate>Sun, 28 May 2023 00:00:00 +0000</pubDate>
      <guid>https://www.davidlang.tech/posts/store-additional-user-information-in-firebase-using-react-and-javascript/</guid>
      <description>&lt;p&gt;To store additional information for a user in &lt;code&gt;Firebase&lt;/code&gt; using React and JavaScript, you typically use Firestore or the Realtime Database, as Firebase Authentication does not allow for arbitrary additional data to be stored directly in user profiles. Here’s a step-by-step guide on how to achieve this using Firestore.&lt;/p&gt;&#xA;&lt;h2 id=&#34;step-1-set-up-firebase-in-your-react-app&#34;&gt;Step 1: Set Up Firebase in Your React App&lt;/h2&gt;&#xA;&lt;p&gt;First, ensure that you have Firebase set up in your React application. You need to install Firebase and initialize it in your project.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Simple Notes app using React, TypeScript, Node.js, GraphQL and MongoDB</title>
      <link>https://www.davidlang.tech/posts/simple-notes-app-using-react-typescript-nodejs-graphql-mongodb/</link>
      <pubDate>Mon, 17 Apr 2023 00:00:00 +0000</pubDate>
      <guid>https://www.davidlang.tech/posts/simple-notes-app-using-react-typescript-nodejs-graphql-mongodb/</guid>
      <description>&lt;p&gt;In the series of the blog post, I am going to walk through step by step process of building a &lt;a href=&#34;https://github.com/rasikjain/SimpleNotes&#34;&gt;Simple Notes&lt;/a&gt; App using &lt;a href=&#34;https://reactjs.org/&#34;&gt;React&lt;/a&gt;, &lt;a href=&#34;https://www.typescriptlang.org/&#34;&gt;TypeScript&lt;/a&gt;, &lt;a href=&#34;https://nodejs.org/en/&#34;&gt;Node.js&lt;/a&gt;, &lt;a href=&#34;https://graphql.org/&#34;&gt;GraphQL &lt;/a&gt;, and &lt;a href=&#34;https://www.mongodb.com/&#34;&gt;MongoDB&lt;/a&gt;. During the process of our development, we are going to use some useful npm packages like &lt;a href=&#34;https://expressjs.com/&#34;&gt;Express&lt;/a&gt;, &lt;a href=&#34;https://www.apollographql.com/docs/apollo-server&#34;&gt;Apollo-Server&lt;/a&gt;, &lt;a href=&#34;https://github.com/typegoose/typegoose&#34;&gt;Typegoose&lt;/a&gt;, &lt;a href=&#34;https://mongoosejs.com/&#34;&gt;Mongoose&lt;/a&gt;, &lt;a href=&#34;https://typegraphql.com/&#34;&gt;TypeGraphQL &lt;/a&gt;, and &lt;a href=&#34;https://getbootstrap.com/&#34;&gt;Bootstrap&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Here is the Github &lt;a href=&#34;https://github.com/rasikjain/SimpleNotes&#34;&gt;Source Code&lt;/a&gt; to run the application.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Table of Content&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://www.davidlang.tech/posts/simple-notes-app-using-react-typescript-nodejs-graphql-mongodb/#dev-environment-setup&#34;&gt;Dev Environment Setup&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://www.davidlang.tech/posts/simple-notes-app-using-react-typescript-nodejs-graphql-mongodb/#graphql-server-backend&#34;&gt;GraphQL Server Backend&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://www.davidlang.tech/posts/simple-notes-app-using-react-typescript-nodejs-graphql-mongodb/#folder-structure&#34;&gt;Folder Structure&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://www.davidlang.tech/posts/simple-notes-app-using-react-typescript-nodejs-graphql-mongodb/#creating-nodejs-project&#34;&gt;Creating Node.js project&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://www.davidlang.tech/posts/simple-notes-app-using-react-typescript-nodejs-graphql-mongodb/#configuring-typescript&#34;&gt;Configuring TypeScript&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://www.davidlang.tech/posts/simple-notes-app-using-react-typescript-nodejs-graphql-mongodb/#installing-dependency-packages&#34;&gt;Installing Dependency Packages&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://www.davidlang.tech/posts/simple-notes-app-using-react-typescript-nodejs-graphql-mongodb/#mongoose-schema-and-graphql-schema&#34;&gt;Mongoose Schema and GraphQL Schema&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://www.davidlang.tech/posts/simple-notes-app-using-react-typescript-nodejs-graphql-mongodb/#graphql-resolvers&#34;&gt;GraphQL Resolvers&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://www.davidlang.tech/posts/simple-notes-app-using-react-typescript-nodejs-graphql-mongodb/#mongo-database-setup&#34;&gt;Mongo Database Setup&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://www.davidlang.tech/posts/simple-notes-app-using-react-typescript-nodejs-graphql-mongodb/#environment-configuration&#34;&gt;Environment Configuration&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://www.davidlang.tech/posts/simple-notes-app-using-react-typescript-nodejs-graphql-mongodb/#nodejs-server-setup&#34;&gt;Node.js Server Setup&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://www.davidlang.tech/posts/simple-notes-app-using-react-typescript-nodejs-graphql-mongodb/#config-files&#34;&gt;Config files&lt;/a&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://www.davidlang.tech/posts/simple-notes-app-using-react-typescript-nodejs-graphql-mongodb/#packagejson&#34;&gt;package.json&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://www.davidlang.tech/posts/simple-notes-app-using-react-typescript-nodejs-graphql-mongodb/#nodemonjson-configuration&#34;&gt;nodemon.json configuration&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://www.davidlang.tech/posts/simple-notes-app-using-react-typescript-nodejs-graphql-mongodb/#running-nodejs--server&#34;&gt;Running node.js / Server&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h3 id=&#34;dev-environment-setup&#34;&gt;Dev Environment Setup&lt;/h3&gt;&#xA;&lt;p&gt;We are going to set up our initial codebase and folder structure to get started. In this tutorial, I am going to use the Windows environment. The command structure is mostly the same and can be easily replicated to macOS.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Differences between getServerSideProps and getStaticProps in Next.js</title>
      <link>https://www.davidlang.tech/posts/differences-between-getserversideprops-and-getstaticprops-in-next.js/</link>
      <pubDate>Tue, 11 Oct 2022 00:00:00 +0000</pubDate>
      <guid>https://www.davidlang.tech/posts/differences-between-getserversideprops-and-getstaticprops-in-next.js/</guid>
      <description>&lt;h3 id=&#34;introduction&#34;&gt;Introduction:&lt;/h3&gt;&#xA;&lt;p&gt;&lt;code&gt;Next.js&lt;/code&gt; is a popular &lt;code&gt;React framework&lt;/code&gt; that enables developers to create server-side rendered applications with ease. Two essential functions in Next.js are &lt;code&gt;getServerSideProps&lt;/code&gt; and &lt;code&gt;getStaticProps&lt;/code&gt;, which help developers pre-render pages and optimize performance. Although they share similarities, they have significant differences in terms of functionality and usage. In this blog, we will explore the differences between getServerSideProps and getStaticProps and provide real-world examples to help you understand their use cases.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Simplifying State Management with React&#39;s useContext Feature</title>
      <link>https://www.davidlang.tech/posts/simplifying-state-management-with-react-usecontext-feature/</link>
      <pubDate>Tue, 19 Jul 2022 00:00:00 +0000</pubDate>
      <guid>https://www.davidlang.tech/posts/simplifying-state-management-with-react-usecontext-feature/</guid>
      <description>&lt;h3 id=&#34;introduction&#34;&gt;Introduction:&lt;/h3&gt;&#xA;&lt;p&gt;React, being a popular JavaScript library for building user interfaces, provides various tools and features to handle state management. One such feature is &lt;code&gt;useContext&lt;/code&gt;, which allows developers to share state across different components without prop drilling. In this blog post, we will explore the &lt;code&gt;useContext&lt;/code&gt; feature in React and demonstrate its usage with a TypeScript example.&lt;/p&gt;&#xA;&lt;h3 id=&#34;understanding-usecontext&#34;&gt;Understanding useContext:&lt;/h3&gt;&#xA;&lt;p&gt;The &lt;code&gt;useContext&lt;/code&gt; hook is part of the React library and allows components to consume values from a provided context. It provides a simple and efficient way to share state between multiple components in a React application. By utilizing &lt;code&gt;useContext&lt;/code&gt;, we can avoid passing props through intermediate components, thereby reducing the complexity of the codebase.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Using React Hooks - useState and useEffect</title>
      <link>https://www.davidlang.tech/posts/using-reactjs-hooks-introduction-usestate-useeffect/</link>
      <pubDate>Tue, 15 Mar 2022 00:00:00 +0000</pubDate>
      <guid>https://www.davidlang.tech/posts/using-reactjs-hooks-introduction-usestate-useeffect/</guid>
      <description>&lt;p&gt;With the release of &lt;a href=&#34;https://reactjs.org/docs/hooks-intro.html&#34; title=&#34;React Hooks&#34;&gt;Hooks&lt;/a&gt; in React 16.8, it is now possible to store &lt;strong&gt;state&lt;/strong&gt; in a &lt;strong&gt;function&lt;/strong&gt;. We can add react features like useState and useEffect into the function directly without needing to create &lt;strong&gt;class&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;h2 id=&#34;usestate&#34;&gt;useState&lt;/h2&gt;&#xA;&lt;p&gt;The &lt;strong&gt;useState&lt;/strong&gt; hook adds state to the functional components. useState hook allows you to declare one state variable at a time.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-react&#34; data-lang=&#34;react&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#268bd2&#34;&gt;import&lt;/span&gt; React, { useState } from &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#39;react&amp;#39;&lt;/span&gt;;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#268bd2&#34;&gt;function&lt;/span&gt; Counter() {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#586e75&#34;&gt;//Declare the &amp;#34;counter&amp;#34; state variable&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#268bd2&#34;&gt;const&lt;/span&gt; [counter, setCounter] &lt;span style=&#34;color:#719e07&#34;&gt;=&lt;/span&gt; useState(&lt;span style=&#34;color:#2aa198&#34;&gt;0&lt;/span&gt;);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#719e07&#34;&gt;return&lt;/span&gt; (&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      &amp;lt;&lt;span style=&#34;color:#268bd2&#34;&gt;div&lt;/span&gt;&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &amp;lt;&lt;span style=&#34;color:#268bd2&#34;&gt;p&lt;/span&gt;&amp;gt;Clicked {counter} times&amp;lt;/&lt;span style=&#34;color:#268bd2&#34;&gt;p&lt;/span&gt;&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#586e75&#34;&gt;//increment the counter by 1 on every click&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &amp;lt;&lt;span style=&#34;color:#268bd2&#34;&gt;button&lt;/span&gt; onClick&lt;span style=&#34;color:#719e07&#34;&gt;=&lt;/span&gt;{() =&amp;gt; setCounter(counter &lt;span style=&#34;color:#719e07&#34;&gt;+&lt;/span&gt; &lt;span style=&#34;color:#2aa198&#34;&gt;1&lt;/span&gt;)}&amp;gt;Click here&amp;lt;/&lt;span style=&#34;color:#268bd2&#34;&gt;button&lt;/span&gt;&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      &amp;lt;/&lt;span style=&#34;color:#268bd2&#34;&gt;div&lt;/span&gt;&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  );&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;useeffect&#34;&gt;useEffect&lt;/h2&gt;&#xA;&lt;p&gt;The &lt;strong&gt;useEffect&lt;/strong&gt; allows to manage side effects in a functional component. Some of the examples are fetching external data using api, manipulating DOM in react. It is similar to componentDidMount and componentDidUpdate from class component.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Modern JavaScript ES2020: Top Features You Should Know</title>
      <link>https://www.davidlang.tech/posts/modern-javascript-es2020-top-features-you-should-know/</link>
      <pubDate>Sat, 28 Nov 2020 00:00:00 +0000</pubDate>
      <guid>https://www.davidlang.tech/posts/modern-javascript-es2020-top-features-you-should-know/</guid>
      <description>&lt;p&gt;ECMAScript 2020 added practical features that reduce boilerplate and improve null-safety. If you are still avoiding optional chaining, now is the time to adopt it.&lt;/p&gt;&#xA;&lt;h2 id=&#34;optional-chaining-and-nullish-coalescing&#34;&gt;Optional Chaining and Nullish Coalescing&lt;/h2&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#268bd2&#34;&gt;const&lt;/span&gt; city &lt;span style=&#34;color:#719e07&#34;&gt;=&lt;/span&gt; user&lt;span style=&#34;color:#719e07&#34;&gt;?&lt;/span&gt;.address&lt;span style=&#34;color:#719e07&#34;&gt;?&lt;/span&gt;.city &lt;span style=&#34;color:#719e07&#34;&gt;??&lt;/span&gt; &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#39;Unknown&amp;#39;&lt;/span&gt;;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;?.&lt;/code&gt; short-circuits on &lt;code&gt;null&lt;/code&gt; or &lt;code&gt;undefined&lt;/code&gt;. &lt;code&gt;??&lt;/code&gt; returns the right side only when the left is &lt;code&gt;null&lt;/code&gt; or &lt;code&gt;undefined&lt;/code&gt;-unlike &lt;code&gt;||&lt;/code&gt;, it preserves &lt;code&gt;0&lt;/code&gt; and &lt;code&gt;&#39;&#39;&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;h2 id=&#34;bigint-and-globalthis&#34;&gt;BigInt and globalThis&lt;/h2&gt;&#xA;&lt;p&gt;&lt;code&gt;BigInt&lt;/code&gt; handles integers beyond &lt;code&gt;Number.MAX_SAFE_INTEGER&lt;/code&gt;. &lt;code&gt;globalThis&lt;/code&gt; provides a standard way to access the global object in browsers and Node.&lt;/p&gt;</description>
    </item>
    <item>
      <title>TypeScript for JavaScript Developers: Getting Started</title>
      <link>https://www.davidlang.tech/posts/typescript-for-javascript-developers-getting-started/</link>
      <pubDate>Sat, 18 Apr 2020 00:00:00 +0000</pubDate>
      <guid>https://www.davidlang.tech/posts/typescript-for-javascript-developers-getting-started/</guid>
      <description>&lt;p&gt;TypeScript adds static types to JavaScript, catching bugs at compile time and improving editor autocomplete. For full stack developers moving between frontend and backend, it is one of the highest-leverage skills to adopt.&lt;/p&gt;&#xA;&lt;h2 id=&#34;installing-and-configuring&#34;&gt;Installing and Configuring&lt;/h2&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;npm install -D typescript @types/node&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;npx tsc --init&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;A sensible &lt;code&gt;tsconfig.json&lt;/code&gt; for Node or React projects enables &lt;code&gt;strict&lt;/code&gt;, &lt;code&gt;esModuleInterop&lt;/code&gt;, and &lt;code&gt;skipLibCheck&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;h2 id=&#34;core-concepts&#34;&gt;Core Concepts&lt;/h2&gt;&#xA;&lt;p&gt;&lt;strong&gt;Interfaces&lt;/strong&gt; describe object shapes. &lt;strong&gt;Generics&lt;/strong&gt; make reusable components type-safe. &lt;strong&gt;Union types&lt;/strong&gt; (&lt;code&gt;string | number&lt;/code&gt;) model values that can be one of several types.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Getting Started with React Hooks: A Complete Guide</title>
      <link>https://www.davidlang.tech/posts/getting-started-with-react-hooks-a-complete-guide/</link>
      <pubDate>Sat, 15 Feb 2020 00:00:00 +0000</pubDate>
      <guid>https://www.davidlang.tech/posts/getting-started-with-react-hooks-a-complete-guide/</guid>
      <description>&lt;p&gt;React Hooks arrived in React 16.8 and changed how we write components. Instead of class components for state and lifecycle logic, you can use functions with &lt;code&gt;useState&lt;/code&gt;, &lt;code&gt;useEffect&lt;/code&gt;, and more.&lt;/p&gt;&#xA;&lt;h2 id=&#34;why-hooks-matter&#34;&gt;Why Hooks Matter&lt;/h2&gt;&#xA;&lt;p&gt;Hooks let you reuse stateful logic without higher-order components or render props. They keep related logic together-fetching data, subscribing to events, and updating the DOM live in one place instead of spread across lifecycle methods.&lt;/p&gt;&#xA;&lt;h2 id=&#34;usestate-and-useeffect&#34;&gt;useState and useEffect&lt;/h2&gt;&#xA;&lt;p&gt;&lt;code&gt;useState&lt;/code&gt; declares local state in a function component. &lt;code&gt;useEffect&lt;/code&gt; runs side effects after render-API calls, subscriptions, or DOM updates.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
