<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nihar Raote on Medium]]></title>
        <description><![CDATA[Stories by Nihar Raote on Medium]]></description>
        <link>https://medium.com/@NAPOLEON039?source=rss-a715828b870b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*VSBYX46Hde8Pt_M-9T3Jdw.jpeg</url>
            <title>Stories by Nihar Raote on Medium</title>
            <link>https://medium.com/@NAPOLEON039?source=rss-a715828b870b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 22:32:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@NAPOLEON039/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to create a simple PostgreSQL database with Expressjs?]]></title>
            <link>https://levelup.gitconnected.com/how-to-create-a-simple-postgresql-database-with-expressjs-1eac74a6bfc6?source=rss-a715828b870b------2</link>
            <guid isPermaLink="false">https://medium.com/p/1eac74a6bfc6</guid>
            <category><![CDATA[expressjs]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[guides-and-tutorials]]></category>
            <dc:creator><![CDATA[Nihar Raote]]></dc:creator>
            <pubDate>Mon, 10 Jul 2023 17:10:34 GMT</pubDate>
            <atom:updated>2023-08-13T16:32:21.930Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to create a simple PostgreSQL database with Expressjs</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AwfeuVzAUhJyYiI6" /><figcaption>Photo by <a href="https://unsplash.com/@clemhlrdt?utm_source=medium&amp;utm_medium=referral">Clément Hélardot</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>PostgreSQL is a powerful database with features like multi-version concurrency control, a customizable storage interface for tables, a robust access-control system, support for full-text search among many others. It can be used with a variety of back-end languages like Nodejs, Rust, Python, Java, etc.</p><p>It is not difficult to setup a PostgreSQL database with a framework like Expressjs. This is a simple guide on creating a set of CRUD APIs. As long as you know the basics of Node and Express, you can follow along. Some experience with SQL databases (especially PostgreSQL) will help you understand this guide much better.</p><h3>Creating an Express server</h3><p>I will be creating a basic Express server:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EBNuJJVmDGk-LtliOl_aXA.png" /><figcaption>A basic Express server</figcaption></figure><h3>A PostgreSQL table</h3><p>We have our express server. Let’s create a table in PostgreSQL. I will log in to the default database with my role and create a new database for our table. There will be a link at the end of this article about creating roles in PostgreSQL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9GyimhsEgFprHUI4ijhaEA.png" /><figcaption>Creating a PostgreSQL table</figcaption></figure><p>Here, with -d we specify a database. postgres is the default one. And -U specifies our role name. My role&#39;s name is personal. I created a database named userAPI and switched to it.</p><p>We have an empty users table in the userAPI database. We need to access this database from Express.</p><h3>Connecting to the database</h3><p>To communicate with our PostgreSQL database and table, we will need a package. The package we will be using is called <a href="https://www.npmjs.com/package/pg"><em>node-postgres</em></a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*--zc0Ubg7sP_-zlHlEJfSA.png" /><figcaption>Installing the package</figcaption></figure><p>Let’s use this package to start a connection with our database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DwgrWOONhrsqp8rpMYimUA.png" /><figcaption>Creating a connection in Express with the database</figcaption></figure><p>We have put the required configuration in a separate file. A new pool of connections is created with the following properties:</p><ol><li>user — This is the user account/role we created that can access the userAPI database.</li><li>host — Since we are hosting Postgres on our own machine, localhost would be used. If you are connecting to a remote PostgreSQL database, then use the remote machine’s address. For eg — <a href="http://86.152.120.12/">http://86.152.120.12</a>.</li><li>database — This is the database we would like to access.</li><li>password — The corresponding password for the user account/role.</li><li>port — By default the port is <em>5432</em>. If you have configured a different port or are connecting to your remote machine, use the appropriate port number.</li></ol><p>We have our Express server, a PostgreSQL database, an empty table, and the server can access the database. Let’s create some APIs.</p><h3>Simple CRUD</h3><p>We will perform simple CRUD operations on our database — creating a new user, reading data about a user, updating a user’s data, and deleting a user.</p><p>We will keep them in a separate file as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EoGw_hWS3jbDmGrhayfN5Q.png" /><figcaption>Create API</figcaption></figure><p>After extracting the name and email sent in the request, we use the query function to create a new record in the database. If you have used MySQL with Express before, this syntax will be very familiar.</p><p>We can read the data for all users or a single one:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b0PIHqbbhmLpJ-tU-BLDZg.png" /><figcaption>Read APIs</figcaption></figure><p>These three functions also demonstrate how parameters are passed to SQL statements in <em>node-postgres</em>. If you have five parameters, then each parameter will be picked from the array in order. For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nkm8tR9Axrii1YPbaQH1Pw.png" /><figcaption>Query example</figcaption></figure><p>Let’s write the update and delete functions:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*di3qj0zFHjm6YA44fpMZZw.png" /><figcaption>Update and delete APIs</figcaption></figure><p>Make sure to export the queries so we can use them to create endpoints:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bWHNmjLwHuPnDYw6nW3fGQ.png" /><figcaption>All API endpoints</figcaption></figure><h3>Conclusion</h3><p>If you have never worked with PostgreSQL before, I hope you try it.</p><p>Here are some additional resources:</p><ol><li>A <a href="https://www.postgresqltutorial.com/postgresql-administration/postgresql-roles/">tutorial</a> on creating roles in PostgreSQL.</li><li><a href="https://www.prisma.io/dataguide/postgresql/benefits-of-postgresql">Why use PostgreSQL</a>?</li><li>How does PostgreSQL stack up against another equally popular database like MongoDB? Read <a href="https://www.mongodb.com/compare/mongodb-postgresql">this article</a> about their differences and how to pick between them.</li><li>A fan of Sequelize? Learn <a href="https://www.robinwieruch.de/postgres-express-setup-tutorial/">how to use</a> it with PostgreSQL and Express.</li><li>After creating a CRUD API with Express and PostgreSQL, you can build a front-end with Vue and have a <a href="https://www.bezkoder.com/vue-node-express-postgresql/">full-stack</a> application.</li></ol><p><em>Originally published at </em><a href="https://dev.to/napoleon039/how-to-create-a-simple-postgresql-database-with-expressjs-58n8"><em>https://dev.to</em></a><em> on July 10, 2023.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1eac74a6bfc6" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/how-to-create-a-simple-postgresql-database-with-expressjs-1eac74a6bfc6">How to create a simple PostgreSQL database with Expressjs?</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Custom React Hooks. What are they and how are they helpful?]]></title>
            <link>https://levelup.gitconnected.com/custom-react-hooks-what-are-they-and-how-are-they-helpful-2251ebead854?source=rss-a715828b870b------2</link>
            <guid isPermaLink="false">https://medium.com/p/2251ebead854</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-hook]]></category>
            <dc:creator><![CDATA[Nihar Raote]]></dc:creator>
            <pubDate>Sun, 04 Sep 2022 19:13:29 GMT</pubDate>
            <atom:updated>2022-09-04T19:13:29.772Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*f9QhtR08-XS2c43M" /><figcaption>Photo by <a href="https://unsplash.com/es/@lautaroandreani?utm_source=medium&amp;utm_medium=referral">Lautaro Andreani</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>React Hooks were introduced in React.js v16.8. They allow us to use state in functional components, similar to the lifecycle hooks of class-based components. For every situation, there is a React Hook you can use. From the frequently used hooks like useState and useEffect to hooks like useCallback and useMemo, you can take your time to browse <a href="https://reactjs.org/docs/hooks-reference.html">the documentation</a> for the hook you need.</p><p>Since there are hooks for almost every situation you might encounter, is there a need for your own React Hook?</p><h3>What are custom hooks?</h3><p>When we want to re-use some logic in multiple places, we extract it to a function. If we also want to re-use some JSX along with it, we extract it to a separate component. Similarly, a React Hook is also a function.</p><p>If we want to create a reusable function that also uses React Hooks like useState and useEffect, we cannot store this logic in a plain function.</p><p>A component can be created to store this reusable logic so we can then use hooks. But this is not ideal if we do not have any JSX to write in that component.</p><p>In such situations, the reusable logic can be extracted to a custom React Hook. Making a custom React Hook is simple — prefix a function’s name with <em>use</em>. For example:</p><figure><img alt="A regular function and a custom React hook prefixed with the word use." src="https://cdn-images-1.medium.com/max/1024/1*MKkICeI8g8Daoqnd1rMffg.png" /><figcaption>A regular function vs a custom React hook.</figcaption></figure><h3>An example of a custom hook</h3><p>Here is some logic that has been extracted into a custom hook.</p><p>The custom hook useSelectClub takes an array of sports clubs as an argument. A person can belong to one or more sports clubs. If a club is marked as a person&#39;s favorite, then that club&#39;s code is returned. If the user belongs to a single club, that club&#39;s code is returned.</p><figure><img alt="A simple example of a custom React hook." src="https://cdn-images-1.medium.com/max/1024/1*Z9qt-Kpo2CLUICO29bDX8A.png" /><figcaption>An example of a custom hook.</figcaption></figure><h3>Wrapping up</h3><p>I hope this short guide helped you to understand custom hooks in React and how to use them.</p><p>Just like how recurring JSX and logic can be turned into reusable components, logic that uses React Hooks can also be turned into reusable custom hooks.</p><p><em>Originally published </em><a href="https://niharraoteblog.netlify.app/custom-react-hooks"><em>on my blog</em></a><em>.</em></p><h3>Level Up Coding</h3><p>Thanks for being a part of our community! Before you go:</p><ul><li>👏 Clap for the story and follow the author 👉</li><li>📰 View more content in the <a href="https://levelup.gitconnected.com/?utm_source=pub&amp;utm_medium=post">Level Up Coding publication</a></li><li>🔔 Follow us: <a href="https://twitter.com/gitconnected">Twitter</a> | <a href="https://www.linkedin.com/company/gitconnected">LinkedIn</a> | <a href="https://newsletter.levelup.dev/">Newsletter</a></li></ul><p>🚀👉 <a href="https://jobs.levelup.dev/talent/welcome?referral=true"><strong>Join the Level Up talent collective and find an amazing job</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2251ebead854" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/custom-react-hooks-what-are-they-and-how-are-they-helpful-2251ebead854">Custom React Hooks. What are they and how are they helpful?</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Improve DOM Structure with React Portal]]></title>
            <link>https://medium.com/geekculture/how-to-improve-dom-structure-with-react-portal-6e6fe249bcc5?source=rss-a715828b870b------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e6fe249bcc5</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[guides-and-tutorials]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Nihar Raote]]></dc:creator>
            <pubDate>Sat, 18 Jun 2022 22:03:08 GMT</pubDate>
            <atom:updated>2022-06-18T22:03:08.204Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*tJjyhDY5-zL5aIE39psK5Q.png" /></figure><h3>What is it?</h3><p>According to the <a href="https://reactjs.org/docs/portals.html">official React documentation</a>,</p><blockquote><em>Portals provide a first-class way to render children into a DOM node that exists outside a DOM hierarchy of the parent component.</em></blockquote><p>Take a look at this example — let’s say you have a Calculator component, inside which there is a Buttons component. It would look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KzM9ul2uXfOx6on8CXTIvg.png" /></figure><p>The root component App along with all its child components will be rendered inside a single DOM node (most likely a div with an id of #root). With React Portal, a child component like Buttons can be rendered outside the div with an id of #root. You can imagine the structure of the DOM to look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yh4m79lqHX5Wun9P-7d4DQ.png" /><figcaption>DOM structure after using React Portal</figcaption></figure><h3>Why should I know this?</h3><p>In certain situations, it is necessary to render some JSX or a component outside the root element. The best example of such a situation would be a modal.</p><p>A modal would typically cover the entire screen. One would expect this to be reflected in the DOM structure as well. However, that’s not what happens in React. If a modal is nested inside a component, that is also how the DOM structure would look like. This can be confusing for people who use screen readers. From an accessibility standpoint, this is an issue.</p><p>Resolving this might be a bit easy to do in Vanilla JS and HTML, but harder to do in React. Since React applications have a single mount point, putting an element or component outside this mount point is a challenge. With React Portal, this becomes an easy task.</p><p>Although the element or component will be <em>portaled</em> to a different DOM node, it will still function as a regular React element. This means that our modal is in a different DOM node than the mount point. But it can still receive props and state and behave like a regular nested React element.</p><h3>How do I use it?</h3><p>Let’s use the modal example from the section above. Creating a React Portal and mounting it to a different DOM node can be done in 2 steps:</p><h3>Step 1:</h3><p>Create another DOM node for mounting the modal:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TSGN1zsY5VUNtL0gGuK8eg.png" /><figcaption>New div in the HTML file</figcaption></figure><p>The React application will be mounted to the div with an id of #root. And the modal will be mounted to the div with an id of #modal-root.</p><h3>Step 2:</h3><p>Create a Portal wrapper component:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fFWreaectsl-8PzE0Bz-eg.png" /><figcaption>Wrapper component that implements React Portal</figcaption></figure><p>This wrapper component will take a child element and create a Portal for it. The useEffect hook mounts the element and cleans up when the component is unmounted.</p><p>Here is how it might look:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IBjKmaqIad6bF5wa1czBVA.png" /><figcaption>Wrapping Modal with the wrapper component</figcaption></figure><p>Even though the Modalcomponent is nested in the app hierarchy, it will look different in the DOM structure:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l4t_C1YmN8NUzJkr0v3evQ.png" /><figcaption>DOM structure after using React Portal on Modal</figcaption></figure><p>In the real DOM structure, you won’t see the Modal component directly like this, but a div instead. This is simply a demonstration.</p><h3>Extra resources</h3><ol><li><a href="https://blog.logrocket.com/learn-react-portals-by-example/">This article</a> has another good use case for using React Portals.</li><li>A <a href="https://malcoded.com/posts/react-portals/">dialog component</a> is also a good scenario where React Portal is quite handy.</li><li>Do you need a ref from a React Portal? Then <a href="https://stackoverflow.com/a/46644072/12903901">this solution</a> for React 16 might help.</li><li>Learn <a href="https://dev.to/alexandprivate/your-next-react-modal-with-your-own-usemodal-hook-context-api-3jg7">how to create</a> a Modal component with React Hooks, Context, and Portals.</li></ol><p><em>Originally published on </em><a href="https://niharraoteblog.netlify.app/guide-to-react-portals"><em>my</em> <em>blog</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e6fe249bcc5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/how-to-improve-dom-structure-with-react-portal-6e6fe249bcc5">How to Improve DOM Structure with React Portal</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[These 3 differences between Reactjs and React Native are easy to spot.]]></title>
            <link>https://medium.com/weekly-webtips/these-3-differences-between-reactjs-and-react-native-are-easy-to-spot-a06a780f16ca?source=rss-a715828b870b------2</link>
            <guid isPermaLink="false">https://medium.com/p/a06a780f16ca</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Nihar Raote]]></dc:creator>
            <pubDate>Tue, 12 Apr 2022 17:56:14 GMT</pubDate>
            <atom:updated>2022-04-21T06:15:51.698Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*4Mp6yLvPE-dQQ3jZEHg6wQ.png" /><figcaption>Cover image</figcaption></figure><h3>What is React Native?</h3><p>It is a JavaScript framework that is used to build cross-platform applications. React Native uses React.js. Because of this, by opening a file from a React Native project, a React developer will find the structure and syntax used quite familiar. A React Native project can be packaged for both Android and iOS.</p><h3>What are the differences between React and React Native code?</h3><p>There are many things that are different between React and React Native. These differences become more prominent the closer we are to production.</p><p>During development, the differences might not seem much, but when pushing the code to a production environment, there is a noticeable difference between the two. After all, for Reactjs, the final result would most probably be a website. For React Native, it would be a mobile app.</p><p>Here are 3 primary differences a Reactjs developer will encounter when working with React Native for the first time.</p><h3>1. Grouping elements</h3><p>In React, to group some elements together and to create visual blocks of code, we mainly use div. Here&#39;s an example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xySxWw1h_7OHEcwm9tAQWw.png" /><figcaption>Grouping elements in Reactjs</figcaption></figure><p>However, this code will not work in React Native. Since React Native code needs to map to native components on mobile, we need to use the View component instead of div. Let&#39;s change the above example to work in React Native:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tdB0t6RxUxYTrWn88R9SKA.png" /><figcaption>Grouping elements in React Native</figcaption></figure><p>Even though React Native uses Reactjs, in the end, the code needs to run on mobile devices. UI components like View help to map React Native code to native UI code.</p><p>So, in a React Native application, divs are no longer used. The View component needs to be used instead. You can think of the View component as React Native&#39;s alternative for div. When it comes to differences between React and React Native, these UI components stand out easily.</p><p>Speaking of differences, did you notice how the row and container classes were applied in React Native? That is the second difference.</p><h3>2. Styling without CSS files</h3><p>Unlike React, React Native does not style components with CSS files. Any styles needed are supposed to be created with the StyleSheet component. Let&#39;s use the example from the first point. This time, take a look at the styles as well:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lkqem3Rnn2I22IhrVQDhiw.png" /><figcaption>Styling in React Native</figcaption></figure><p>Does this look familiar? It should. This is similar to how inline styles are written in React. There are also a few differences.</p><p>In React, padding: &#39;20px&#39; would be a typical line in an inline style. In React Native, this would instead be padding: 20. Of course, something like padding: &#39;5%&#39; is written the same way in React Native.</p><p><em>Do keep in mind that some style attributes might not work with relative units like </em><em>% em rem.</em> If you want to use these relative units for these attributes, there is a package available. It will be linked at the end of this article.</p><p>Another thing to keep in mind is that the shorthand syntax for various CSS attributes is not available in React Native. For example, take a look at the following comparison between a property inside a CSS file and its equivalent in React Native:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jk-VBkn3lblcL_6PjSh1uw.png" /><figcaption>CSS attribute shorthands</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XgZvrh5izs_FhqeWqBeXqA.png" /><figcaption>No shorthand in React Native</figcaption></figure><p>Although these longhand forms can also be used in CSS, it’s the shorthand form that is usually used for convenience. In React Native, however, these shorthands cannot be used.</p><h3>3. Default layout for all elements</h3><p>In React Native, all components have a display of flex and direction of column applied by default. So there is no need to specify display: flex. Since flexbox is enabled everywhere by default, it becomes easier to style the layout.</p><p>I found it a little confusing in the beginning since I was used to the default flex-direction of a row. Over time I <em>did</em> get used to the column direction but do keep that flex-direction in mind before you start styling a bunch of nested components.</p><p>I think this default direction makes sense if you consider how a mobile device is usually held in portrait mode.</p><h3>Wrapping up</h3><p>These are some of the few differences that will seem unfamiliar to you when working with React Native for the first time. Pushing a React Native app to production can seem confusing to a developer who has never experienced that before.</p><p>This is also what makes React Native easier to get started with if you have worked with Reactjs.</p><p>The differences between React Native and React are because of different targets — a mobile application instead of a web application. Other than that, the rest of the development experience is similar to working with Reactjs.</p><h3>Helpful resources</h3><ol><li><a href="https://www.npmjs.com/package/react-native-responsive-screen">This package</a> is a workaround for using the percentage unit for a responsive UI.</li><li>The official documentation on deploying React Native applications for both <a href="https://reactnative.dev/docs/signed-apk-android">Android</a> and <a href="https://reactnative.dev/docs/publishing-to-app-store">iOS</a> is well written.</li><li><a href="https://instabug.com/blog/react-native-app-ios-android/">Here</a> is another great article on deploying React Native applications.</li><li><a href="https://docs.expo.dev/">Expo</a> is a framework that helps quickly develop, build, and deploy React Native applications.</li><li>Does your React Native application have a complex navigation structure? <a href="https://medium.com/@jan.hesters/building-a-react-native-app-with-complex-navigation-using-react-navigation-85a479308f52">This article</a> might help you out.</li></ol><p><em>Originally published on </em><a href="https://niharraoteblog.netlify.app/react-native-three-differences-from-react"><em>my blog</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a06a780f16ca" width="1" height="1" alt=""><hr><p><a href="https://medium.com/weekly-webtips/these-3-differences-between-reactjs-and-react-native-are-easy-to-spot-a06a780f16ca">These 3 differences between Reactjs and React Native are easy to spot.</a> was originally published in <a href="https://medium.com/weekly-webtips">Webtips</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Context and Hooks: Pass data and update it easily]]></title>
            <link>https://itnext.io/react-context-and-hooks-pass-data-and-update-it-easily-d2f659cceab?source=rss-a715828b870b------2</link>
            <guid isPermaLink="false">https://medium.com/p/d2f659cceab</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Nihar Raote]]></dc:creator>
            <pubDate>Mon, 28 Mar 2022 19:58:43 GMT</pubDate>
            <atom:updated>2022-03-28T19:58:43.495Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*Sgb_s4UICBLvwG3dae83eg.png" /><figcaption>Cover image</figcaption></figure><p>In the <a href="https://itnext.io/react-context-and-hooks-an-excellent-way-to-pass-data-26c3f48b9bf5">previous article</a>, we looked at what Context is and how to pass values with it. In this article, we will look at updating the Context value from the child component. For our theme example, this means clicking the button will now switch the theme between light and dark.</p><h3>Updating Context value</h3><p>In the previous article, we directly passed the theme via the Provider component. Although the value is passed to ThemeButton.js and ThemeWindow.js components, we cannot update this value.</p><p>To switch between the two theme types, we need to pass a function as well. This function will allow us to switch between both themes.</p><p>So we need to pass this function along with the dark theme via the Provider component. To do this, we can create a stateful object which will contain both the theme and a function. This way React can keep track of the theme and perform the necessary re-renders when it updates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FHqFaFdV7TWRCye_" /><figcaption>Creating a stateful object</figcaption></figure><p>This is pretty straightforward. A stateful object containing a theme type and a function is passed via the Provider component. While the ThemeWindow component only needs minor changes, we do need to implement the function in the ThemeButton component.</p><h3>Implementing theme switch function</h3><p>Nothing special needs to be done to implement the function. Calling it when the button is pressed will switch the theme.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*d3Svr-PtL6YHMeGH" /><figcaption>Add theme switch function to ThemeButton component</figcaption></figure><p>As easy as that. When this button is clicked, the switchTheme() function will be executed. This will update the stateful value and thus trigger a re-render. And finally, the updated theme will be rendered in the ThemeWindow component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RIFKJSG92gGNUHfw" /><figcaption>Reflecting minor changes in the ThemeWindow component</figcaption></figure><h3>Wrapping up</h3><p>This was the conclusion to the previous article about React Context. As you have seen, React Context is a powerful tool.</p><p>However, this simple example does not really showcase its power. In complex applications with dozens of components, where values and state need to be passed to several different components, React Context will make this job far easier than regular props.</p><p><em>Originally published on </em><a href="https://niharraoteblog.netlify.app/update-context-from-child-component"><em>my blog</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d2f659cceab" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/react-context-and-hooks-pass-data-and-update-it-easily-d2f659cceab">React Context and Hooks: Pass data and update it easily</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Context and Hooks: An excellent way to pass data]]></title>
            <link>https://itnext.io/react-context-and-hooks-an-excellent-way-to-pass-data-26c3f48b9bf5?source=rss-a715828b870b------2</link>
            <guid isPermaLink="false">https://medium.com/p/26c3f48b9bf5</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[context-api]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Nihar Raote]]></dc:creator>
            <pubDate>Wed, 26 Jan 2022 09:59:28 GMT</pubDate>
            <atom:updated>2022-02-01T10:24:12.356Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wSa3Up0rzS7XLSlp" /><figcaption>Photo by <a href="https://unsplash.com/@lautaroandreani?utm_source=medium&amp;utm_medium=referral">Lautaro Andreani</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>What is Context?</h3><p>A Context is basically a JavaScript object that can be passed from one parent component to several child components efficiently. Props can pass values to components as well. But, if a value needs to be passed to a child component deep in the component tree, using props means the value also passes through components that do not need it. Or, if a value is required by several components, props can make it difficult.</p><p>This is a good use case for Context. Props need to be passed from one component to the other. With Context, the parent component provides the value, and the child components that need it can access it.</p><h3>Passing values with Context and Hooks</h3><p>Let’s take a common example used for demonstrating Context — themes. Consider the following UI:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*18v3guVWDCgIz6mO2AFWgg.png" /></figure><p>Here, the one with the red border is the main App.js component. The one with the green border is a component called ThemeButton.js and the one with a blue border is the ThemeWindow.js component. The App component will have the other two as its child components. Clicking the button in ThemeButton will toggle the theme between light and dark. The result of the theme will be reflected in ThemeWindow.</p><p>We need to create a context first, then have the App component <em>provide</em> a value for its child components. The child component(s) will <em>consume</em> this provided value. Let&#39;s set this up.</p><h3>1. Creating a context</h3><p>A context can be created in a separate file or in the App component itself, but it is generally better to create a separate file for it. Since depending on your app, you may need multiple contexts for different features. It can thus be useful to have separate files.</p><p>Create a new file to hold the context and export it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cEVAQ4Za-YhVCXy4ZbAZzQ.png" /><figcaption>Creating a context and a themes object</figcaption></figure><p>In this file, we export two things — an object containing theme values and our context. The createContext() function returns a Context object. It accepts an argument for the initial value similar to the useState hook. In this case, the light themes object is the default value of ThemeContext.</p><h3>2. Passing values with the Provider component</h3><p>Since the context has been created, let’s add it in App.js.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DJJFPYXUl14sOhe6sM_ung.png" /><figcaption>The Provider component is something that React provides when a Context object is created</figcaption></figure><p>Every Context object (created with React.createContext()) has a <strong>Provider</strong> component. This Provider component should be wrapped around all the child components that will be getting access to ThemeContext. Conversely, there is also a <strong>Consumer</strong> component. You can also use the useContext hook instead if you&#39;re not working with class-based components.</p><p>You must be wondering why the <strong>light</strong> object was used as the default value, but the Provider component has passed the <strong>dark</strong> object. First of all, the value prop used in the Provider component is something React recognizes so you cannot use a different name for that prop.</p><p>Whatever is passed through the value prop is what the child components consume. And if a component attempts to access ThemeContext but does not have a <strong>Provider</strong> component in the tree above, it will use the default value the Context object has (the light theme).</p><p>As a quick example, let’s say there was a third component called ThemeFont.js. But this third component was not included within the Provider component -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IdUN3YOVsIBiMcoE2N-94g.png" /><figcaption>The ThemeFont component is outside the scope of the Provider component</figcaption></figure><p>Since ThemeFont is not wrapped by the Provider component, it will not receive the new value. Although it can still access ThemeContext, it will receive the default value, that is, the value we passed to createContext - the light themes object.</p><blockquote><em>Not wrapping a component that needs access to a Context in a Provider component still gives it access to the Context’s default value.</em></blockquote><p>Though, you probably wouldn’t face such a situation frequently. A component that requires the value(s) from a Context but cannot be wrapped in the Provider component ― this situation is quite rare.</p><h3>3. Consuming context in child components</h3><p>Let’s use React Hooks to consume the provided context value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v5z-grBfGCZ-QWlht75p7w.png" /><figcaption>Similar to the Provider component, there is a Consumer component also available after creating the Context object. It can be used instead of useContext</figcaption></figure><p>Running this app, you would get the following result:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fvh0nd&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fvh0nd&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fvh0nd%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/03e644f0dfdf96c1414b38ea06f6e36b/href">https://medium.com/media/03e644f0dfdf96c1414b38ea06f6e36b/href</a></iframe><p>The ThemeWindow certainly has a dark theme. But, the button to toggle the theme doesn&#39;t work. The next article will demonstrate how to update values passed via Context.</p><h3>Some links to resources</h3><ul><li><a href="https://kentcdodds.com/blog/how-to-use-react-context-effectively">How to use React Context effectively</a> by <a href="https://twitter.com/kentcdodds">Kent C. Dodds</a></li><li><a href="https://reactjs.org/docs/context.html">React Context official docs</a></li></ul><p><em>Originally published on </em><a href="https://niharraoteblog.netlify.app/intro-to-context"><em>my blog</em></a><em> on January 14, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26c3f48b9bf5" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/react-context-and-hooks-an-excellent-way-to-pass-data-26c3f48b9bf5">React Context and Hooks: An excellent way to pass data</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How many lines would it take to animate a button? GSAP makes it easy]]></title>
            <link>https://levelup.gitconnected.com/how-many-lines-would-it-take-to-animate-a-button-gsap-makes-it-easy-1fd02df20969?source=rss-a715828b870b------2</link>
            <guid isPermaLink="false">https://medium.com/p/1fd02df20969</guid>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[gsap]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Nihar Raote]]></dc:creator>
            <pubDate>Sun, 26 Sep 2021 17:24:25 GMT</pubDate>
            <atom:updated>2021-09-26T17:24:25.746Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rafS76IKF7CytVW9" /><figcaption>Photo by <a href="https://unsplash.com/@jstrippa?utm_source=medium&amp;utm_medium=referral">James Harrison</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In this article, I implement a simple button animation with GSAP and use the Composition API introduced in Vue 3.x. If you are not familiar with the Composition API, you can refer to the resources linked at the end of the article.</p><h3>What is GSAP?</h3><p>GSAP (GreenSock Animation Platform) is a JavaScript animation library that allows developers to create powerful animations with few lines of code. With this library, you get more precise control over your animations, which makes it easier to create complex animations. The GSAP library is small in size, easy to use, and works consistently across browsers with under-the-hood calculations.</p><h3>Simple button animation</h3><p>I have created a simple form and used GSAP to run an animation when the submit button is clicked. For this, I used the Composition API and ref from Vue. The animation itself takes only two lines of code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CUxH2WAkrfFfUxfQ3Zqkbw.png" /><figcaption>Button animation code</figcaption></figure><p>Here’s the codepen; you can tweak around to make some cool form animations as well:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2FNAPOLEON039%2Fembed%2Fpreview%2FNWgboLZ%3Fdefault-tabs%3Djs%252Cresult%26height%3D600%26host%3Dhttps%253A%252F%252Fcodepen.io%26slug-hash%3DNWgboLZ&amp;display_name=CodePen&amp;url=https%3A%2F%2Fcodepen.io%2FNAPOLEON039%2Fpen%2FNWgboLZ&amp;image=https%3A%2F%2Fassets.codepen.io%2F1283738%2Finternal%2Fscreenshots%2Fpens%2FNWgboLZ.default.png%3Ffit%3Dcover%26amp%3Bformat%3Dauto%26amp%3Bha%3Dtrue%26amp%3Bheight%3D360%26amp%3Bquality%3D75%26amp%3Bv%3D2%26amp%3Bversion%3D1631017281%26amp%3Bwidth%3D640&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/f4039d67ed4f6c2aaae4bdd2ca55e794/href">https://medium.com/media/f4039d67ed4f6c2aaae4bdd2ca55e794/href</a></iframe><p>Resources</p><ul><li><a href="https://ihatetomatoes.net/simple-greensock-tutorial-your-first-steps-with-gsap/">Simple GreenSock Tutorial</a> by <a href="https://twitter.com/ihatetomatoes">Petr Tichy</a></li><li><a href="https://www.freecodecamp.org/news/the-beginners-guide-to-the-greensock-animation-platform-7dc9fd9eb826/">A Beginner’s Guide to GreenSock</a> by <a href="https://www.linkedin.com/in/nicholas-kramer-3574b463/">Nicholas Kramer</a></li><li><a href="https://css-tricks.com/how-to-animate-on-the-web-with-greensock/">How to Animate on the Web With GreenSock</a> by <a href="https://twitter.com/sarah_edo">Sarah Drasner</a></li><li><a href="https://v3.vuejs.org/api/composition-api.html">Official Vue docs on Composition API</a></li><li><a href="https://www.codemag.com/Article/2011041/Vue&#39;s-Composition-API">Vue Composition API</a> by <a href="https://twitter.com/ShawnWildermuth">Shawn Wildermuth</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1fd02df20969" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/how-many-lines-would-it-take-to-animate-a-button-gsap-makes-it-easy-1fd02df20969">How many lines would it take to animate a button? GSAP makes it easy</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make a Simple React App With Webpack — An Easy Practical Guide]]></title>
            <link>https://medium.com/geekculture/make-a-simple-react-app-with-webpack-an-easy-practical-guide-8a8839665fbd?source=rss-a715828b870b------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a8839665fbd</guid>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[webdev]]></category>
            <dc:creator><![CDATA[Nihar Raote]]></dc:creator>
            <pubDate>Thu, 29 Apr 2021 12:32:49 GMT</pubDate>
            <atom:updated>2021-04-29T12:32:49.144Z</atom:updated>
            <content:encoded><![CDATA[<h3>Make a Simple React App With Webpack — An Easy Practical Guide</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*E_M7kvrn72uWzSsA0pYB8g.png" /></figure><p>Create React App is the first choice of most, if not all, React developers. It creates a React project for us and only requires a few commands. Its simplicity and quick nature make it a favorite among beginners as well. But, there are also ways to create a React app without it.</p><p>One of these ways is using a module bundler like Webpack and a compiler like Babel.</p><p>By the end of this article, you will have your very own React app without using create-react-app.</p><h3>Dependencies and project structure</h3><p>Since this React app will use the Webpack module bundler, we need to install quite a few dependencies. These dependencies are required by Webpack so it can detect and work with the various file types.</p><p>Here’s what we need to install:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FWH9D4YXKf_iTOu4" /></figure><p>These two packages are the dependencies we need for our simple app. If your project needs any other packages, you may install those.</p><p>There are close to 10 devDependencies, so let’s install them in groups and I’ll explain what each dependency is for. First comes webpack:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xWOnASKVXNIV8Oq3" /></figure><ul><li>webpack: Installs the webpack module bundler</li><li>webpack-cli: Offers a variety of commands that make it easier to work with webpack on the command line</li><li>webpack-dev-server: Allows us to use a simple web server with hot reload</li></ul><p>Next, we’ll install Babel:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*phGOCNXOZYfvAuMb" /></figure><ul><li>@babel/core: Core package for the Babel compiler</li><li>@babel/preset-env: A smart preset that allows us to use the latest JavaScript syntax</li><li>@babel/preset-react: As the name suggests, it transpiles React code to plain JavaScript</li><li>babel-loader: A plugin that enables Webpack to work with Babel and its presets</li></ul><p>The remaining devDependencies are for CSS and HTML:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*l-XmbtaN0gceYUyA" /></figure><ul><li>style-loader, css-loader: Required so that webpack can detect .css files</li><li>html-webpack-plugin: Generates an HTML file that includes all your Webpack bundles via script tags</li></ul><p>Everything a basic React project needs is installed. Now create these folders and file in the project’s root:</p><ol><li>A public folder for the HTML file and assets (images, fonts, etc.)</li><li>A src folder for .js files and React components</li><li>A babel.config.json Babel configuration file</li></ol><p>At this point, your project folder should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/815/0*CWQ3PbngEnYlGOku" /></figure><h3>Webpack and Babel config</h3><p>Let’s add the presets in the Babel config file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sXlJyKXldyWHWhmO" /></figure><p>It is recommended to have two separate config files for Webpack — one for development and one for production. Although both files will have the same configuration for loaders and any plugins, there are slight differences. This is what a config file for development looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xXtcbZHwZqDo5q9y" /></figure><p>Here, we first declare the mode configuration option. With this, Webpack can use its built-in optimizations accordingly. Next, module.rules is an array containing 3 objects:</p><ol><li>This rule tells Webpack to look for files ending in .js and use Babel to compile them. babel-loader helps Webpack work with Babel.</li><li>The second rule tells Webpack to look for files ending in .css and make sense of them with the help of two loaders - style-loader and css-loader.</li><li>The last rule helps Webpack recognize image files. There is no need to install any external loader for this.</li></ol><blockquote><strong><em>Note</em></strong><em>: According to the Webpack docs, </em><em>style-loader and </em><em>css-loader need to be used in the exact same order as in this config file or it won&#39;t work.</em></blockquote><p>After loaders, we have two plugins. When Webpack bundles all JavaScript, CSS, and other necessary files, it also creates an HTML file. This is where we use the html-webpack-plugin. This plugin tells Webpack to use our HTML file as a template and inject the compiled bundles into it.</p><p>So, instead of creating its own HTML file, Webpack instead uses <em>our</em> HTML file — public/index.html and adds the bundled files to it via &lt;script&gt; tags.</p><p>The other plugin we use is HotModuleReplacementPlugin which comes with the webpack package and is used for hot reloading our app in development mode.</p><p>Finally, the devServer object contains options used by webpack-dev-server.</p><p>Now let’s take a look at the production version of the configuration file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Db0IU_edsgfLTtGU" /></figure><p>Not much has changed except that we no longer need HotModuleReplacementPlugin and devServer since they will not be used in production. The mode option has also been set accordingly. You might have noticed the changes in output.</p><p>output.filename has a value that we haven&#39;t seen before. The values in square brackets are tokens. The [name] token allows Webpack to name files differently if we use code-splitting. [contenthash] is used so that the bundle file name changes when its content changes.</p><h3>Running the app</h3><p>Our app is almost ready. I have a simple App.js component:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GMJ_cWA1bapFPYrY" /></figure><p>The app folder looks like this now:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/0*OGQbnrOVlGN21JGP" /></figure><p>Finally, we need to add scripts to run our app:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nJDa64vKs9wT49xk" /></figure><p>With the serve option Webpack uses webpack-dev-server to create a web server. Let&#39;s run our app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QaI3zsdB7en0oERX" /></figure><p>Open https://localhost:8080 in your browser and your app should be running.</p><h3>Wrapping up</h3><p>This is a basic React app where we manually configure Webpack. I hope this helped you to understand a bit about the various plugins and loaders Webpack requires and what its configuration files look like. The Webpack documentation is worth reading. It was the major resource I used for this article.</p><p>In comparison, <a href="https://parceljs.org/getting_started.html">Parcel</a> uses very few dependencies. I wrote another article about creating a <a href="https://levelup.gitconnected.com/how-to-create-a-minimal-react-and-parcel-app-in-5-steps-2806fa09a371">React app with Parcel</a>. That said, both have their own pros and cons.</p><p>Here are links to some additional resources:</p><ol><li><a href="https://webpack.js.org/configuration/">Webpack documentation</a> on config files and the various options a config file can have</li><li>Webpack documentation on <a href="https://webpack.js.org/guides/asset-management/#loading-css">loading CSS</a> and other assets</li><li>Webpack documentation on <a href="https://webpack.js.org/guides/development/#using-webpack-dev-server">webpack-dev-server</a> and <a href="https://webpack.js.org/plugins/html-webpack-plugin/#basic-usage">html-webpack-plugin</a></li><li>An article from <a href="https://twitter.com/carlrippon">Carl Rippon</a> on creating a <a href="https://www.carlrippon.com/creating-react-app-with-typescript-eslint-with-webpack5/">React app</a> that uses TypeScript and ESLint with Webpack 5</li><li>Babel documentation on its <a href="https://babeljs.io/docs/en/configuration">config files</a></li></ol><p><em>Originally published on </em><a href="https://niharraoteblog.netlify.app/webpack-react-app"><em>my blog</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a8839665fbd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/make-a-simple-react-app-with-webpack-an-easy-practical-guide-8a8839665fbd">Make a Simple React App With Webpack — An Easy Practical Guide</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How do closures make private variables possible in JavaScript?]]></title>
            <link>https://javascript.plainenglish.io/how-do-closures-make-private-variables-possible-in-javascript-e4c0adf3f64b?source=rss-a715828b870b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4c0adf3f64b</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Nihar Raote]]></dc:creator>
            <pubDate>Fri, 12 Mar 2021 14:01:41 GMT</pubDate>
            <atom:updated>2021-03-12T14:01:41.391Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oVZLqxZLn8iPctiQpavAdQ.png" /></figure><p>Being able to implement private variables and methods is very helpful for restricting access to code. By making a variable private it limits the amount of code that can mutate it. There are several ways to implement private variables and methods in JavaScript. One of such ways is by using closures.</p><h3>What is a closure?</h3><p>A closure is the combination of a function bundled with its surrounding state. This means that we can access the scope in which the function is defined, from inside that function. Let’s look at a simple example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EcdB5BP3ILqxXhrB" /><figcaption>An example of a closure</figcaption></figure><p>Here we have an outer function add and an inner function addFive. Assigning add to a variable will return the inner function addFive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sLawvsp3Gs3lpkqd" /><figcaption>Executing closure example</figcaption></figure><p>Invoking the variable and passing a number will execute addFive. At first, it seems accessing x should not be possible since x belongs to the scope of the outer function which has already finished executing. But, because the function addFive forms a closure, it also has access to the environment or scope in which it was declared (also known as the lexical environment).</p><p>If a function forms a closure, it can access variables and functions declared in the parent/outer function even after that parent/outer function finishes executing. This principle allows us to implement private variables.</p><h3>Implementing private variables</h3><p>In JavaScript, private variables are not natively available. But knowing how closures work, we can emulate them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NuFsxHM3TkVZ3T4M" /><figcaption>Implementing private variables</figcaption></figure><p>This example applies the concept we looked at in the previous section. An IIFE(Immediately Invoked Function Expression) is assigned to the constant Door. The IIFE executes immediately and returns an object with two methods. This returned object has a function and a variable in its lexical environment.</p><p>The IIFE finishes executing, so the variable and function are both inaccessible from the outside. Only the two methods inside the returned object can access them because they form closures.</p><p><em>Originally published on </em><a href="https://niharraoteblog.netlify.app/javascript-closures"><em>my blog</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4c0adf3f64b" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/how-do-closures-make-private-variables-possible-in-javascript-e4c0adf3f64b">How do closures make private variables possible in JavaScript?</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to query with GraphQL? Is it really better than Rest?]]></title>
            <link>https://medium.com/weekly-webtips/how-to-query-with-graphql-is-it-really-better-than-rest-4fe002c48689?source=rss-a715828b870b------2</link>
            <guid isPermaLink="false">https://medium.com/p/4fe002c48689</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[frontend]]></category>
            <dc:creator><![CDATA[Nihar Raote]]></dc:creator>
            <pubDate>Wed, 10 Mar 2021 16:47:21 GMT</pubDate>
            <atom:updated>2021-03-10T17:29:23.566Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to query with GraphQL?</h3><h4>Is it really better than Rest?</h4><figure><img alt="How to query with GraphQL?" src="https://cdn-images-1.medium.com/max/1012/1*bOkB3KtU78gHMJWvoRPSeQ.png" /></figure><p>Getting too much data than what is needed, getting less data than we want, querying multiple endpoints for required data. These are some of the things we have to accept when working with RestAPIs. Almost anyone who has worked with databases has experienced this.</p><p>But GraphQL is different. Writing a single query is enough to give us the data we want. Here are some of the points that make GraphQL queries more efficient and intuitive -</p><ol><li>Nesting related data</li><li>Getting the data we ask for, nothing more, nothing less</li><li>Defining the shape of the query result with our queries</li></ol><p>So what does a GraphQL query look like? How do you determine what the structure of the query result will be regardless of how the data is fetched? Do you really get what you ask for without anything extra? Let’s find out.</p><h3>Is GraphQL different from a database?</h3><p>GraphQL is indeed different from databases like SQLite, MongoDB, and Firebase. It is a query language for APIs. While databases store data, GraphQL can help us fetch that data more efficiently. What makes GraphQL different from usual methods of fetching data is the amount of control we have.</p><p>Generally, we send a request to the database or the server asking for the required data. Even though the data might be organized in tables (like in SQLite) or some other format (like Firebase, where each data entry is a document), most of the time, we get more than what we may require. So it now comes to us to sift through that data and look for what we need.</p><h3>An example</h3><p>Here’s a simple example from Firebase. Let’s say you have a database with a collection of cities. Each city is a document inside that collection containing the name of the city and other information like the temperature, population, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*U8sW0PRQX4feXcUJ" /><figcaption>Firestore database of cities</figcaption></figure><p>You only want the temperature of a particular city. So, you write a query with the name of the city as a condition. Firebase gives you the document where the city’s name is the one you specified and then you extract the temperature of the city from the result Firebase gave you. This process might look something like this -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*e8VrSmh6JuZMQvyX" /><figcaption>Fetching from Firestore</figcaption></figure><p>At first glance, this is a regular query giving us what we asked for. But what about that extra information that comes along with the temperature? Can GraphQL do a better job?</p><h3>The GraphQL way</h3><p>To get the same data, with GraphQL, we first have to define a schema -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZuvB4OkEkxz2PHK_" /><figcaption>A schema for GraphQL queries</figcaption></figure><p>This is a GraphQL schema. It tells GraphQL what a possible query might be and anything related it needs to know regarding that query.</p><p>Here, we have defined a possible query called city which will have an argument. This argument will be the name of the city we want to fetch data for. This city query will return a data type of City. We have also defined what this City data type looks like and the various fields it includes. Now we can write a query -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xv7hvhCZHmssN4b6" /><figcaption>Fetching from Firestore using a GraphQL query</figcaption></figure><p>That’s it! This is all we need and GraphQL gives us exactly what we asked for in the same format -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CImGwq1Kkk4nSYQp" /><figcaption>Data returned from GraphQL</figcaption></figure><p>We have exactly what we need. No extra information, no need to invoke a chain of object properties to get the data we want.</p><p>Of course, behind the scenes, we still have to actually fetch the data from Firebase. And the way this data is fetched is the same as what we did before. So, what’s the difference?</p><p>The most notable difference is the query size and refactoring time. This is what makes GraphQL so efficient to work with. The GraphQL query when compared to the Firebase code we wrote before is quite small. Adding new queries or refactoring existing ones also requires less time.</p><p>Fetching new data requires you to consider where and how the data is nested or you may have to fetch it from a different endpoint. With GraphQL, all you need to consider is how the new data relates to the current query.</p><p>After fetching the temperature of a specific city from a group of cities, if you want to fetch the details of a user living in that city, no need to write a different query:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GUS4M39BFBcyqqv9" /><figcaption>Modifying GraphQL query for fetching additional data</figcaption></figure><p>Even though the user’s data might be in a different collection, our query does not require any major changes.</p><h3>Wrapping up</h3><p>Ultimately, when we actually fetch the data from a database, GraphQL is no different from RestAPIs. The advantage with using GraphQL however comes with where this data fetching occurs.</p><p>Using RestAPIs, we need to change our queries and possibly refactor code when the required data changes. When using GraphQL, we define what to fetch, how to fetch it, where to fetch it from and GraphQL takes care of the rest. Essentially, after we tell GraphQL how to fetch data we get the data we want in the required form with queries.</p><p>The data fetching process is already defined, all we have to change are the queries. This makes GraphQL better to work with than RestAPIs in some situations.</p><p>Does this mean you’re better off using GraphQL than RestAPIs? Not at all. Both have their own pros and cons depending on where they are used. The choice you make between either should be based on what your project needs. If you need caching on requests, … then RestAPIs will suit your needs better.</p><p>GraphQL can do much more than simply fetch data from databases. The official <a href="https://graphql.org/learn">documentation</a> is worth reading to know more. If you want to learn how to implement GraphQL in the language you want, <a href="https://www.howtographql.com/">here</a> is a series of tutorials from Prisma.</p><p><em>Originally published on </em><a href="https://niharraoteblog.netlify.app/how-to-query-with-graphql"><em>my blog</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4fe002c48689" width="1" height="1" alt=""><hr><p><a href="https://medium.com/weekly-webtips/how-to-query-with-graphql-is-it-really-better-than-rest-4fe002c48689">How to query with GraphQL? Is it really better than Rest?</a> was originally published in <a href="https://medium.com/weekly-webtips">Webtips</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>