<?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 Amjad Nazeer on Medium]]></title>
        <description><![CDATA[Stories by Amjad Nazeer on Medium]]></description>
        <link>https://medium.com/@amjadnaz1000?source=rss-72c1312fb3ea------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Y8R85moBywDEzVQ4.</url>
            <title>Stories by Amjad Nazeer on Medium</title>
            <link>https://medium.com/@amjadnaz1000?source=rss-72c1312fb3ea------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 01:38:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@amjadnaz1000/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[Streamlining Development Workflow: Harnessing Husky and Lint-staged for React/TypeScript Projects]]></title>
            <link>https://medium.com/@amjadnaz1000/streamlining-development-workflow-harnessing-husky-and-lint-staged-for-react-typescript-projects-342c8c5c4876?source=rss-72c1312fb3ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/342c8c5c4876</guid>
            <dc:creator><![CDATA[Amjad Nazeer]]></dc:creator>
            <pubDate>Tue, 14 May 2024 23:40:51 GMT</pubDate>
            <atom:updated>2024-05-14T23:40:51.372Z</atom:updated>
            <content:encoded><![CDATA[<p>As a Senior Developer, I’m always on the lookout for tools and practices that can streamline our workflow and boost productivity. In my journey of optimizing our company’s codebases, I stumbled upon a powerful duo of tools: <a href="https://typicode.github.io/husky/">Husky</a> and <a href="https://www.npmjs.com/package/lint-staged">Lint-staged</a>. These tools, when combined, offer a seamless way to automate essential tasks like linting, formatting, type-checking, and running tests before committing changes in ourReact/TypeScript and Next.js projects. Let me share my experience and the advantages I’ve witnessed firsthand.</p><h3>Automating Quality Checks</h3><p>One of the most significant advantages of Husky and Lint-staged is the ability to enforce coding standards and best practices automatically. With Husky, we can set up Git hooks to trigger actions at specific points in our Git workflow. Lint-staged complements this by allowing us to run scripts on staged files. Together, they ensure that every commit adheres to predefined standards.</p><h3>Linting and Formatting</h3><p>Maintaining a consistent code style across a project can be challenging, especially in a team environment. However, with tools like ESLint and Prettier integrated into our workflow through Husky and Lint-staged, this became a breeze. we can define our linting rules and formatting preferences and have them applied automatically to staged files before each commit.</p><p>We use <a href="https://www.npmjs.com/package/prettier">Prettier</a> for Formatting our codebase and it’s an awesome tool and should be a go to for all developers</p><p>This not only improves code readability but also minimizes the need for manual intervention.</p><p>Although sometimes it’s a pain when it keeps throwing errors and you gotta go back and fix em. but in the long run the codebase looks so much cleaner.</p><p>Here’s the prettier config we use, this works pretty well for us:</p><pre>{<br>  &quot;arrowParens&quot;: &quot;avoid&quot;,<br>  &quot;bracketSameLine&quot;: false,<br>  &quot;bracketSpacing&quot;: true,<br>  &quot;embeddedLanguageFormatting&quot;: &quot;auto&quot;,<br>  &quot;htmlWhitespaceSensitivity&quot;: &quot;css&quot;,<br>  &quot;insertPragma&quot;: false,<br>  &quot;jsxSingleQuote&quot;: false,<br>  &quot;printWidth&quot;: 120,<br>  &quot;proseWrap&quot;: &quot;preserve&quot;,<br>  &quot;quoteProps&quot;: &quot;as-needed&quot;,<br>  &quot;requirePragma&quot;: false,<br>  &quot;semi&quot;: false,<br>  &quot;singleAttributePerLine&quot;: true,<br>  &quot;singleQuote&quot;: true,<br>  &quot;tabWidth&quot;: 2,<br>  &quot;trailingComma&quot;: &quot;all&quot;,<br>  &quot;useTabs&quot;: false,<br>  &quot;vueIndentScriptAndStyle&quot;: false<br>}</pre><h3>Type-Checking with TypeScript</h3><p>For TypeScript projects, type-checking is crucial for catching errors early in the development process. By leveraging Husky and Lint-staged to run the TypeScript compiler (tsc) on staged files, we ensure that our codebase remains type-safe at all times.</p><p>This proactive approach reduces the likelihood of runtime errors and enhances overall code quality.</p><h3>Test Automation</h3><p>Running tests before pushing code to the repository is a fundamental practice in our development workflow. With Husky and Lint-staged, we integrate our testing framework (Jest) into the pre-commit hook, ensuring that all tests pass before changes are committed. This helps prevent regressions and maintains the stability of your application.</p><h3>Improved Productivity</h3><p>By automating these essential tasks, I and the team focus more on writing code and less on manual maintenance activities. The time saved from manually running linters, formatters, type-checkers, and tests adds up significantly over the course of a project. Moreover, the confidence gained from knowing that every commit meets the project’s quality standards boosts team morale and accelerates development velocity.</p><h3>Getting Started</h3><p>Implementing Husky and Lint-staged in your React/TypeScript projects is pretty straightforward. Begin by installing them as dev dependencies:</p><pre>npm install --save-dev husky lint-staged</pre><p>Next run</p><pre>npx husky init</pre><p>The init command simplifies setting up husky in a project. It creates a pre-commit script in .husky/ and updates the prepare script in package.json.</p><p>You should have a command under scripst in your package.json:</p><pre>&quot;prepare&quot;: &quot;husky install&quot;,</pre><p>Then, define your lint-staged configuration (we use a <strong>lintstagedrc</strong> file):</p><pre>{<br>  &quot;*.+(js|ts|tsx)&quot;: [&quot;eslint&quot;],<br>  &quot;**/*.+(js|ts|tsx|json|html|css)&quot;: [&quot;prettier --write&quot;, &quot;git add&quot;]<br>}</pre><p>Replace the commands above with your preferred tools and scripts according to your project’s requirements.</p><p>Our pre-commit file in <em>.husky l</em>ooks like this</p><pre>npm run check-types &amp; npx lint-staged &amp; npm run test &amp; npm run build<br></pre><p>If all the steps above are correct, when you commit a change you should get something like this before the commit goes through:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A3J8dIRM1s0yDrTncp0ZIg.png" /></figure><p><em>PS: If you’re using VS Code’s integrated GIT terminal to commit changes, Sometimes if there are errors the commit might throw an popup, better to use the terminal to commit your changes</em></p><h3>Conclusion</h3><p>In conclusion, incorporating Husky and Lint-staged into our React/TypeScript projects significantly enhanced our development workflow. <br>By automating linting, formatting, type-checking, and testing tasks, we ensure code quality, reduce manual effort, and boost productivity across our team.</p><p>Give these tools a try and experience the difference firsthand in your projects. Hope this helps, Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=342c8c5c4876" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PDF Generation in Next.js with react-pdf and a fix for image loading Woes]]></title>
            <link>https://medium.com/@amjadnaz1000/pdf-generation-in-next-js-with-react-pdf-and-a-fix-for-image-loading-woes-6655a1d22b90?source=rss-72c1312fb3ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/6655a1d22b90</guid>
            <dc:creator><![CDATA[Amjad Nazeer]]></dc:creator>
            <pubDate>Wed, 17 Apr 2024 02:19:39 GMT</pubDate>
            <atom:updated>2024-04-17T02:19:39.725Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QxksaRYGhjbmgZCHtZjR0Q.jpeg" /></figure><p>Hey there fellow devs! Today, I’m excited to share with you a handy tool that can spruce up your <a href="https://nextjs.org/">Next.js</a> applications: <a href="https://react-pdf.org/">react-pdf</a>. This nifty library allows you to effortlessly generate PDF documents right within your React components. Whether you need to generate invoices, reports, or any other printable documents, react-pdf has got your back.</p><h3>Getting Started with react-pdf in Next.js</h3><p>First things first, let’s get react-pdf set up in our <a href="https://nextjs.org/">Next.js</a> app. Luckily, it’s a breeze:</p><ol><li>Installation: Start by installing the library using npm or yarn:</li></ol><pre>npm install @react-pdf/renderer</pre><p>or</p><pre>yarn add @react-pdf/renderer</pre><p>2. Importing: Next, import the necessary components in your React file:</p><pre>import { Document, Page, Text } from &#39;@react-pdf/renderer&#39;;</pre><p>3. Usage: Now you’re ready to start creating PDFs! Here’s a basic example to get you going:</p><pre>import { Document, Page, Text } from &#39;@react-pdf/renderer&#39;;<br><br>const MyDocument = () =&gt; (<br>  &lt;Document&gt;<br>    &lt;Page&gt;<br>      &lt;Text&gt;Hello, react-pdf!&lt;/Text&gt;<br>    &lt;/Page&gt;<br>  &lt;/Document&gt;<br>);<br><br>export default MyDocument;</pre><h3>Dealing with Image Loading Woes</h3><p>Ah, but no journey is without its bumps in the road, right? One hiccup I encountered while using react-pdf in my app was loading images from AWS S3. It seemed like some images just refused to cooperate.</p><p>After some head-scratching and a bit of trial and error, I stumbled upon a solution that did the trick. Instead of simply passing the image URL to the source prop of the Image component, I had to go a step further:</p><pre>&lt;Image<br>  source={{<br>    uri: logoURL,<br>    method: &#39;GET&#39;,<br>    headers: {<br>      &#39;Cache-Control&#39;: &#39;no-cache&#39;<br>    },<br>    body: &#39;&#39;<br>  }}<br>/&gt;</pre><h3>Why This Works</h3><p>So, why did this seemingly convoluted piece of code fix the image loading issue? Well, it all boils down to how AWS S3 handles requests for images. By explicitly specifying the request method as ‘GET’ and including a &#39;Cache-Control&#39;: &#39;no-cache&#39; header, we ensure that the image is fetched correctly each time without relying on any potentially problematic caching mechanisms.</p><p>And there you have it! With react-pdf and Next.js by your side, creating beautiful PDF documents is a breeze. Happy coding!</p><p>Now, if you have any questions or need further clarification on anything, feel free to ask away!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6655a1d22b90" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Promise.all() using Async/Await]]></title>
            <link>https://medium.com/@amjadnaz1000/promise-all-using-async-await-90c98bbc209?source=rss-72c1312fb3ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/90c98bbc209</guid>
            <category><![CDATA[asyncawait]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[asynchronous]]></category>
            <category><![CDATA[promises]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Amjad Nazeer]]></dc:creator>
            <pubDate>Sun, 24 May 2020 17:45:13 GMT</pubDate>
            <atom:updated>2020-05-25T03:34:15.441Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qyPL9KsBYioRuI8sCXQSbA.jpeg" /></figure><p>I was working on a feature for my organisation <a href="http://wisenet.co/">wisenet.co</a> and realised I needed to update an array of items from a list, basically selecting multiple items and (let’s say) approving them, I have to update the status of each of the selected items form ‘unApproved’ to ‘approved’. For this I figured I’ll have to use something like promise.all() to approve all the items and get back one single array of results.</p><p>If you need to learn more about promise.all() check this <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all">link</a>.</p><p>But the problem now is, I’m using the newer <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function">async/await</a> syntax to write nicer and cooler looking asynchronous request, so I did some research and found a nice and easy way to do it by combining both Promise.all() and async/Await to give me the desired behaviour I wanted.</p><p>For this example I’m using this dummy Rest API generator called <a href="https://jsonplaceholder.typicode.com/">https://jsonplaceholder.typicode.com/</a> to get the list of todos by ID.</p><p>First I have an array of todo ids that I need to fetch in parallel (for the sake of this example).</p><pre>const todoIds = [1, 2, 3, 4, 5];</pre><p>Next I have a simple function to generate the url:</p><pre>const url = (id) = {<br> return `https://jsonplaceholder.typicode.com/todos/${id}`<br>}</pre><p>Next I have the function to to fetch each individual todo item by id: (note: I’m using the fetch API here, for more info click this <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch">link</a>.</p><pre>const getTodo = async (id) =&gt; {</pre><pre><em> return</em> <em>await </em>fetch(url(https://medium.com/id))<br>  .then(response =&gt; response.json());</pre><pre>};</pre><p>You can wrap this in a Try-Catch block to handle errors I’m leaving it like this for the sake of simplicity.</p><p>Finally I use a Promise.all() combined with async/await to fetch all the todo items in parallel and get the results in one array:</p><pre>const getTodos = async () =&gt; {<br>   <br> try {<br>  return <em>await</em> Promise.all(<br>   todoIds.map(id =&gt; getTodo(id))<br>  );</pre><pre> } catch (error) {<br>    throw error;<br> }</pre><pre>};</pre><p>Here I await a Promise.all() which accepts an array of promises and returns one single array of the results if resolved or throws an error. I have wrapped this function to handled any errors thrown.</p><p>If you run <strong><em>getTodos() </em></strong>you should get an array of objects like:</p><pre>getTodos().then(result =&gt; console.log(result));</pre><pre>[{…}, {…}, {…}, {…}, {…}]</pre><p>I hope this simple article helped you get around whatever bug/rut you’re stuck in, I didn&#39;t want to go into deeper explanation for each and every line since I just want to keep it short and simple. If I have made any mistakes or if there is a better way of doing this please leave a comment. Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=90c98bbc209" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>