<?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 Gabriel Linassi on Medium]]></title>
        <description><![CDATA[Stories by Gabriel Linassi on Medium]]></description>
        <link>https://medium.com/@gabrielm-linassi?source=rss-7cf6a748ec6a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*bVQlc8uVDdbwVBvQTpxrnQ.png</url>
            <title>Stories by Gabriel Linassi on Medium</title>
            <link>https://medium.com/@gabrielm-linassi?source=rss-7cf6a748ec6a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 12:46:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gabrielm-linassi/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 implement layout variants in NextJS (A/B testing)?]]></title>
            <link>https://itnext.io/how-to-implement-layout-variants-in-nextjs-a-b-testing-a3841d340db?source=rss-7cf6a748ec6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3841d340db</guid>
            <category><![CDATA[a-b-testing]]></category>
            <category><![CDATA[nextjs]]></category>
            <dc:creator><![CDATA[Gabriel Linassi]]></dc:creator>
            <pubDate>Thu, 09 Mar 2023 04:26:12 GMT</pubDate>
            <atom:updated>2023-03-16T08:13:03.800Z</atom:updated>
            <content:encoded><![CDATA[<p>Learn how to implement layout testing with static site generation (SSG) with all your variants cached and dynamically accessible through URL query param or persisted cookie.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/0*P7zStdbk_OE3kr96.png" /><figcaption>Layout A/B testing</figcaption></figure><p>Designers come up with all sorts of requests, and in my case it was no different. They had 2 layout variations they wanted to test. So, if the user had accessed any page of the site with the query param variant=a|b it should persist it to the cookies and render the specific layout variation from that moment forwards.</p><h4>TL;DR Source code for the full implementation at the end.</h4><p>Initially, I thought about 2 solutions: <br>1. Create a hook to check the URL query param or cookie client-side and render the correct layout<br>2. Use getServerSideProps to read the URL query params and cookies and pass it down to the client</p><p>Turns out both solutions have considerable drawbacks I was really not interested in.</p><p>The client-side approach (1) throws away caching and also introduces a problem with Cumulative Layout Shift (CLS). To workaround CLS, I would have o add a splash screen or something else.</p><p>The server-side approach (2) also throws away caching and could mean an increase in expenses due to server overload.</p><p>The best solution would be to find a way to cache it by relying on getStaticProps. I thought about it and came up with the following pattern which I’m validating. It relies on:<br>- getStaticPaths<br>- getStaticProps <br>- Context<br>- middleware</p><p>We’ll use the getStaticPaths to generate the paths for all variants, so instead of having a route like / , it will create the variations /a and /b if we have variants a|b.</p><pre>// An example of how getStaticPaths would be to <br>// generate all paths for the variants<br><br>type PageProps = {<br>  variant: &quot;a&quot; | &quot;b&quot;;<br>};<br><br>export const getStaticPaths: GetStaticPaths&lt;PageProps&gt; = () =&gt; {<br>  return {<br>    paths: [{ params: { variant: &quot;a&quot; } }, { params: { variant: &quot;b&quot; } }],<br>    fallback: false,<br>  };<br>};</pre><p>Since the page now accepts multiple variant routes, we need to adjust the file name accordingly. This is the home page and was previously named index.ts It will now be renamed to [variant].ts</p><p>Then we’ll use getStaticProps to to fetch any data we may need and pass down to the client its variant which we’ll store in the Context so it’s avaiable through all the site.</p><pre>// pages/[variant].tsx<br>export const getStaticProps: GetStaticProps&lt;any, PageProps&gt; = async ({<br>  params,<br>}) =&gt; {<br>  return {<br>    props: {<br>      initialVariant: params?.variant,<br>    },<br>  };<br>};<br><br><br>// _app.tsx<br>export default function App({ Component, pageProps }: AppProps) {<br>  return (<br>    &lt;VariantsProvider initialVariant={pageProps.initialVariant ?? &quot;a&quot;}&gt;<br>      &lt;Component {...pageProps} /&gt;<br>    &lt;/VariantsProvider&gt;<br>  );<br>}<br><br><br>// Variant Context implementation<br>import React from &quot;react&quot;;<br><br>type Variant = &quot;a&quot; | &quot;b&quot;;<br><br>type VariantsContextProps = {<br>  variant: Variant;<br>};<br><br>const VariantsContext = React.createContext&lt;VariantsContextProps&gt;({<br>  variant: &quot;a&quot;,<br>});<br><br>type VariantsProviderProps = {<br>  children: React.ReactNode;<br>  initialVariant: Variant;<br>};<br><br>export const VariantsProvider = ({<br>  children,<br>  initialVariant,<br>}: VariantsProviderProps) =&gt; {<br>  return (<br>    &lt;VariantsContext.Provider value={{ variant: initialVariant }}&gt;<br>      {children}<br>    &lt;/VariantsContext.Provider&gt;<br>  );<br>};<br><br>export const useVariantsContext = () =&gt; {<br>  return React.useContext(VariantsContext);<br>};<br></pre><p>Lastly, we’ll use middleware to grab the query param and persist it to the cookies and rewrite the URL to the specified layout variant</p><pre>import { NextRequest, NextResponse } from &quot;next/server&quot;;<br><br>export function middleware(req: NextRequest) {<br>  const url = req.nextUrl;<br><br>  const variantParam = url.searchParams.get(&quot;variant&quot;);<br>  const variantCookie = req.cookies.get(&quot;variant&quot;)?.value;<br><br>  const variant = variantParam ?? variantCookie ?? &quot;a&quot;;<br>  const response = NextResponse.rewrite(new URL(variant, url));<br><br>  if (variantParam) {<br>    response.cookies.set(&quot;variant&quot;, variantParam);<br>  }<br><br>  return response;<br>}<br><br>export const config = {<br>  // match all request paths except for public, api, assets and _next<br>  matcher: &quot;/((?!api|static|.*\\..*|_next).*)&quot;,<br>};</pre><p>That’s pretty much it. With it, you already have the basic structure to layout more complex patterns.</p><p><a href="https://github.com/gabrielmlinassi/nextjs-ssg-layout-variants-poc">Source code for the full implementation</a></p><p>Thanks for the read.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3841d340db" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/how-to-implement-layout-variants-in-nextjs-a-b-testing-a3841d340db">How to implement layout variants in NextJS (A/B testing)?</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[Nice way to abstract your data fetching logic in React with TypeScript]]></title>
            <link>https://levelup.gitconnected.com/nice-way-to-abstract-your-data-fetching-logic-in-react-with-typescript-bbc4552930c8?source=rss-7cf6a748ec6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/bbc4552930c8</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Gabriel Linassi]]></dc:creator>
            <pubDate>Wed, 12 Oct 2022 03:26:10 GMT</pubDate>
            <atom:updated>2022-10-16T13:27:28.136Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to normalize, transform and separate DTO and App interfaces in order to create a better Developer Experience.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*r9aQtHH3i2_t3IL4.jpeg" /><figcaption>Data fetching in React</figcaption></figure><p>Most web apps rely on some sort of server-side interaction and REST is by far the most widely used architecture for that purpose. However, it’s common to receive bloated responses from REST API calls with too much data or, on the contrary, too little.</p><p>Some samples of bloated API responses may be for example these:</p><ul><li><a href="https://pokeapi.co/api/v2/pokemon/1">https://pokeapi.co/api/v2/pokemon/1</a></li><li><a href="http://3.212.60.101/wp-json/wp/v2/posts">http://3.212.60.101/wp-json/wp/v2/posts</a></li></ul><p>I say bloated because we may not need all the fields available in the response. Besides, we may want to change the casing of the fields to follow the patterns already in place in our app or compute new fields on the flow or add new defaults or even grab new data from other endpoints to complement the current one.</p><p>There are multiple ways to do it in React but I’ll propose here a folder/file structure with a specific logic that seems to deal well with these cases. The steps are these:</p><ul><li>Isolate the fetching logic into a service folder</li><li>Add a layer of abstraction between the API response and the App</li><li>Return function response as an object</li><li>Correctly assert the TS typings with Discriminated Union</li></ul><p>So let’s say we want to create a function to get pokemon details by its ID. Let’s first create a folder services/pokemon with the following structure:</p><pre>|<br>|-services<br>|--pokemon<br>|---api.ts<br>|---utils.ts<br>|---typings.ts<br>|---getPokemonDetails.ts<br>|---index.ts<br>|</pre><p><strong>/services:</strong> folder containing all data fetching logic of the application<br><strong>/pokemon:</strong> folder with all fetching logic related to pokemon<br><strong>/api.ts:</strong> file with the api instance for pokemon related fetching logic<br><strong>/utils.ts:</strong> file with utility functions for pokemon related fetching logic<br><strong>/getPokemonDetails.ts:</strong> file with logic to fetch a pokemon details<br><strong>/index.ts:</strong> barrel file containing all exports<br><strong>/typings.ts:</strong> common interfaces used across different pokemon related functions</p><p>I did this separation because if you have more services, then it’s easier to manage but for simplicity, I’ll add everything to the same file.</p><p>For the api.ts file, you could use Axios to create an instance and set up interceptors.</p><p>Here’s the fun part. For the getPokemonDetails.ts file I propose to do it like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/25d466be0e26fb3421261f0983df1b83/href">https://medium.com/media/25d466be0e26fb3421261f0983df1b83/href</a></iframe><p>Notice how I’m transforming the data. That’s related to what I said about bloated responses. Pokemon api returns too much data but for this App, I just need what’s declared in the interface PokemonDetails. If you want to type your API response, which I highly suggest, I propose using the terminology PokemonDetailsDTO. DTO stands for Data Transfer Object and means the data that’s being transferred/received from the server.</p><p>Also, notice the utility function getIdFromUrl. This API response returns the Id but let’s suppose it just returned the URL. This utility function would be useful to create this calculated field and we would do this in this layer instead of inside the React component. We want to deliver the data to the component already baked so it doesn’t need to know anything about the logic or possibly mismatched defaults.</p><p>Lastly, notice how the function response is returned as an object. I find this pattern pretty clean. You don’t need to write try/catch blocks inside of your React components and you can easily get the right data typing with the help of these handy typescript patterns.</p><p>You can also build a custom hook to isolate the logic from your React Component like so and you can add SWR or ReactQuery on top of that for Cache management.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/75d45de1cf30c70e30563ac53bf80faf/href">https://medium.com/media/75d45de1cf30c70e30563ac53bf80faf/href</a></iframe><p>If you’re interested in how to achieve a similar pattern with ReactQuery or SWR where you can also have a layer to perform your data transformations, I suggest you take a look at this pattern:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/256dc60dc41b7978954efaec84a79489/href">https://medium.com/media/256dc60dc41b7978954efaec84a79489/href</a></iframe><p>That’s all. Hope this pattern makes sense to you and let me know if you have any feedback on it. Thanks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bbc4552930c8" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/nice-way-to-abstract-your-data-fetching-logic-in-react-with-typescript-bbc4552930c8">Nice way to abstract your data fetching logic in React with TypeScript</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 incrementally load transparent images with NextJS]]></title>
            <link>https://gabrielm-linassi.medium.com/how-to-incrementally-load-transparent-images-with-nextjs-28ca5fdc8d6b?source=rss-7cf6a748ec6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/28ca5fdc8d6b</guid>
            <category><![CDATA[nextjs]]></category>
            <dc:creator><![CDATA[Gabriel Linassi]]></dc:creator>
            <pubDate>Wed, 17 Nov 2021 18:20:14 GMT</pubDate>
            <atom:updated>2021-11-17T18:20:14.050Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*iscGh1C8UEYu0WDC2CzJaA.png" /><figcaption>on the left is using plaiceholder lib and on the right is a custom hook + custom component. You can see the second takes into account the transparent pixels.</figcaption></figure><p>With NextJS 11 things started to get easier to add image placeholders to have the nice <em>incremental loading effect on images</em>. With that, came some third-party libs to make it easier to generate the small base64 string necessary to add the <a href="https://nextjs.org/docs/api-reference/next/image#blurdataurl">blurDataURL Image’s property on the Image component</a>. One of these libs is <a href="https://github.com/joe-bell/plaiceholder">plaiceholder</a> however, these libs don’t play nicely with transparent png images because <strong>they don’t take into account the transparent pixels</strong> to generate the small base64 string.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eVnsjONi4fGvJ4NcCEoSZw.gif" /><figcaption>gif representing the issue. You can see the image has a transparent bg but with plaiceholder it doesn’t take it into account</figcaption></figure><h3>The solution</h3><p>The solution I came up with was to manually resize the png image to something like 50x50. Then pass the small and original images to a custom hook which returns the small image’s src while the large one has not yet loaded.</p><p>The custom hook:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k32cpdwhtxQMxnWDJNFohQ.png" /><figcaption>custom hook</figcaption></figure><p>The custom image component:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L18NJI6DmnwVEt7fDZ331g.png" /><figcaption>custom image component</figcaption></figure><p>How to call them (both plaiceholder &amp; with custom component)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MEBc3UuiLoTyk4AN7b12Ww.png" /><figcaption>how to use it</figcaption></figure><p>Repo:<br><a href="https://github.com/GabrielmLinassi/incremental-image-loading">https://github.com/GabrielmLinassi/incremental-image-loading</a></p><p>Live:<br><a href="https://incremental-image-loading.vercel.app/">https://incremental-image-loading.vercel.app/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28ca5fdc8d6b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Adding texture to a GLSL Shader Material on React-Three-Fiber]]></title>
            <link>https://gabrielm-linassi.medium.com/adding-texture-to-a-glsl-shader-material-on-react-three-fiber-612c7db7cc4?source=rss-7cf6a748ec6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/612c7db7cc4</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[threejs]]></category>
            <category><![CDATA[react-three-fiber]]></category>
            <dc:creator><![CDATA[Gabriel Linassi]]></dc:creator>
            <pubDate>Sun, 17 Oct 2021 02:28:49 GMT</pubDate>
            <atom:updated>2021-10-17T02:28:49.805Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a quick walkthrough on how to add a texture to a shader with R3F.</p><h3>Steps</h3><ol><li>Import your texture <em>with</em> useLoader and TextureLoader</li></ol><p>2. You can use a primitive model like a Sphere or a custom one created on Blender for example. In this case, make sure to covert your custom 3D model to JSX <em>with</em> this awesome tool: <a href="https://gltf.pmnd.rs/">https://<em>gltf.pmnd.rs/</em></a></p><p>3. pass your texture to the custom material component following the syntax uniforms={{ globeTexture: { value: texture } }}</p><p>4. Add the required GLSL syntax on the sample to apply the image</p><p><strong>PS<em>.</em> Don’t name your GLSL variable of `texture` because it seems it conflicts with some other internal prop. I renamed to globeTexture.</strong></p><p>Full sample:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fdivine-shape-wqf6f%3Ffile%3D%2Fsrc%2FApp.js&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fdivine-shape-wqf6f%3Ffile%3D%2Fsrc%2FApp.js&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fwqf6f%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/b40964371b6c2a9f9544c27156009283/href">https://medium.com/media/b40964371b6c2a9f9544c27156009283/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=612c7db7cc4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Workaround for aspect-ratio on Safari]]></title>
            <link>https://gabrielm-linassi.medium.com/workaround-for-aspect-ratio-on-safari-25699f6d8f31?source=rss-7cf6a748ec6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/25699f6d8f31</guid>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Gabriel Linassi]]></dc:creator>
            <pubDate>Thu, 09 Sep 2021 04:21:56 GMT</pubDate>
            <atom:updated>2021-09-09T04:26:28.731Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t4R5hBJaPdYdrHIKTeTBDA.png" /></figure><p>Safari is really behind compared to other mainstream browsers on several nice CSS features what makes it a real pain to develop smooth and responsive interfaces across a huge range of different devices.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EwHbwijM94vTMK3L01C7XA.png" /></figure><p>Currently, aspect-ratio is only supported on iOS v15 so no chance to use it. Looking around on the internet, you’ll find some pure CSS techniques to solve the problem but I tried all and none worked as I needed. The only solution I found that works great is by calculating the aspect ratio using javascript.</p><p>Below is the app I built for demo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QHTq-2hOhmhmBPgGaJN6Ow.png" /></figure><p>So as you can see I wanted to make a rectangle that has a width of 384px (w-96 tailwind) and aspect-ratio of 9:16. The aspect-ratio property will calculate the height based on the value I passed to it.</p><h3>The height will be 384 * 16 / 9 = ~682.66px</h3><p>However, it doesn’t work on most versions of Safari iOS. So my workaround is to calculate it dynamically using JS below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eOsUFdMTf97bkz12olOpZQ.png" /></figure><p>Basically what I do here is to set a ref to the div element I want to apply the aspect-ratio and get the width or height then do the math. I need one of the dimensions to calculate the other, I believe that’s how aspect-ratio works.</p><h3>Height = width * 16 / 9<br>Width = height * 9 / 16</h3><p>Below is the full gist. Hope it can be useful for someone, thanks!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/12a266fcc980c1183691114da9468a0b/href">https://medium.com/media/12a266fcc980c1183691114da9468a0b/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25699f6d8f31" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building incremental image loading with Next.js 11 & Cloudinary]]></title>
            <link>https://gabrielm-linassi.medium.com/building-incremental-image-loading-with-next-js-11-cloudinary-1a5d3db13b1a?source=rss-7cf6a748ec6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a5d3db13b1a</guid>
            <category><![CDATA[front-end-developer]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[nextjs]]></category>
            <dc:creator><![CDATA[Gabriel Linassi]]></dc:creator>
            <pubDate>Mon, 12 Jul 2021 11:42:12 GMT</pubDate>
            <atom:updated>2021-07-12T11:44:41.883Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TmaXahYmsJa6-mMx.png" /></figure><p>Next.js 11 was released and has brought lots of nice features and improvements. In this tutorial, I’ll talk about the <strong>placeholder </strong>&amp; <strong>blurDataURL </strong>properties added to the Image component and how we can leverage it to build a progressive image loading effect like the ones here on Medium posts. All this keeping the native next Image component optimizations and best practices. On top of it, I added TypeScript and TailwindCSS as my preference but feel free to go with different approaches.</p><h3><strong>Bootstrapping the project</strong></h3><p>First of all, let’s create a new project with tailwind template running the first line of command below. After, we need to install <strong>Cloudinary </strong>to handle Cloudinary resources and <strong>base64-arraybuffer</strong> to convert a buffer to base64, as this is the type required by the blurDataURL property.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LdfVympw-KqZhQ9FYT0GKg.png" /><figcaption>Bootstrap project with npx and install dependencies</figcaption></figure><p>Next.js supports TypeScript natively, so it’s pretty easy to enable it. Just create a file named <strong>tsconfig.json</strong> on the root directory and run <strong>yarn dev</strong>.<strong> </strong>Next will populate the file with default configs for you.</p><h3><strong>Quick side note</strong></h3><p>Next.js 11 made it super easy to create this incremental loading effect. We just have to add<strong> placeholder=`blur`</strong> for the blur transition effect and add the <strong>base64 string on the blurDataURL</strong> property which will be used as the low-resolution image while the original size is not loaded yet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LMlogNUB_RFMyDuE" /><figcaption>Quick sample</figcaption></figure><p><strong>However…</strong> we usually don’t have the images and the base64 stored locally. Often it’s fetched from a CMS or whatnot. Besides, it would be great if there was a way to create the low-resolution base64 automatically for us. That’s where Cloudinary comes into place. Cloudinary is awesome for delivering images super-fast across its CDN and making transformations without effort. This setup is pretty much what’ll be doing in the next sections.</p><h3><strong>Set up Cloudinary</strong></h3><p>Before going further, you need to create an account on Cloudinary and then upload some images on it (heavy preferably, to see the effect). Then select all images and add a tag onto them so it’s easier to find.</p><figure><img alt="Add media &amp; tags on Cloudinary" src="https://cdn-images-1.medium.com/max/1024/1*znTKKV_n6b4r5l7KYucteQ.gif" /><figcaption>How to add media &amp; tags on Cloudinary</figcaption></figure><h3><strong>Walkthrough</strong></h3><p>For maximum performance, I’ll serve this page statically so the base64 image and the URL for fetching the original image will already be present on the app and so won’t require extra HTTP requests and processing to generate them.</p><p>That said, we can create a file in the pages directory that’ll serve as our route and component. I named it <strong>gallery.tsx</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EfOE9dIbi3frBMmLtKuKqw.png" /><figcaption>pages/gallery.tsx</figcaption></figure><p>I chose to place the getPictures method in the API folder so if I need to reuse the logic in the client I can call the internal API endpoint to get the same data.</p><p>To add the file, go to pages/api and create a new file named pictures.ts and add the logic below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IAtyyI_zShvWAvDi" /><figcaption>pages/api/pictures.ts</figcaption></figure><p>Notice we’re not exporting a default function from this api route. We’re just placing it here to keep the code organized and well-architected if we intend to reuse this logic in other places.</p><p>First, we get all the resources by the tag name then map through it to get the thumbnail URL as it does not return on the response JSON. Remember to pass the same tag name as the one you assigned to the images on Cloudinary.</p><p>Nice, now we have the URLs however the blurDataURL requires a base64 string. So we need to fetch the URL which returns an array buffer and then use the method encode from the lib base64-arraybuffer to encode the array buffer into base64 string.</p><p>We do all this in the function fetchBase64 which is being executed in parallel and then we wait for all results using Promise.all. As the Promise.all outputs the array of promises in the same sequence as the input, we can correlate them by the index to generate the response object to be returned.</p><p>Least, don’t forget to create a .env file and declare the variables with your Cloud name, API Key and Secret.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3a8hFZorhWvUrVQ6Ei8UWA.png" /><figcaption>.env file</figcaption></figure><p>This wraps up this tutorial. Hope you liked it. I’m still new to writing tutorials so let me know if there’s something I can improve, any errors, etc.</p><p>Thanks for your time!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a5d3db13b1a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a carousel with react-spring-carousel-js]]></title>
            <link>https://gabrielm-linassi.medium.com/build-a-carousel-with-react-spring-carousel-js-45b68fa22523?source=rss-7cf6a748ec6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/45b68fa22523</guid>
            <category><![CDATA[carousel]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-spring]]></category>
            <dc:creator><![CDATA[Gabriel Linassi]]></dc:creator>
            <pubDate>Thu, 06 May 2021 13:37:01 GMT</pubDate>
            <atom:updated>2021-05-06T13:37:01.172Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ll walk you through how to create a carousel with <a href="https://react-spring-carousel-js.emilianobucci.com/">react-spring-carousel </a>package. Here’s a demo of what we’ll build:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FJa9Z4k5MqMZFbHZkjk%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FJa9Z4k5MqMZFbHZkjk%2Fsource.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FJa9Z4k5MqMZFbHZkjk%2F200.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="172" frameborder="0" scrolling="no"><a href="https://medium.com/media/e8472a7a5a344d87bcbbbbb3ca47421b/href">https://medium.com/media/e8472a7a5a344d87bcbbbbb3ca47421b/href</a></iframe><p>First, let’s bootstrap our React App and install the required dependencies:</p><pre>npx create-react-app .<br>yarn add react-spring-carousel styled-components</pre><p>For reference, this is going to be the final folder structure:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/232/1*wBa2seDhQRlM0-tovMrZbw.png" /><figcaption>Folder structure</figcaption></figure><h3>Let’s get started</h3><p>Create a <strong>items.json file on src/assets</strong> to place our dummy data then paste in this JSON:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/617bef0916122b5fc00255a7dcb6f1c0/href">https://medium.com/media/617bef0916122b5fc00255a7dcb6f1c0/href</a></iframe><p>Going forward, let’s call the ProductList Component on the App Component</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/715870f28f0d9b4a34d70d4b5e5b9ef0/href">https://medium.com/media/715870f28f0d9b4a34d70d4b5e5b9ef0/href</a></iframe><p>Then create a folder <strong>components/products and add the file ProductList.jsx </strong>with the code below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c821786571ad3599263d11caf15e8523/href">https://medium.com/media/c821786571ad3599263d11caf15e8523/href</a></iframe><p>This is the code for the ProductItem which calls the Carousel. Place it on <strong>components/products/Product.jsx</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c352122d61e340ec39babf2379c2e33/href">https://medium.com/media/4c352122d61e340ec39babf2379c2e33/href</a></iframe><p>Here’s the Carousel and CarouselItem with the arrows to scroll the images</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48a050d8810ac16a86195a12cd3a8cbf/href">https://medium.com/media/48a050d8810ac16a86195a12cd3a8cbf/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c5220b8c61372928ced108589fa6e00/href">https://medium.com/media/1c5220b8c61372928ced108589fa6e00/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb651dc1f1877aaa8f2bea69932e5e5f/href">https://medium.com/media/eb651dc1f1877aaa8f2bea69932e5e5f/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/969c5c0a25aa6ab66cb6e83069b510dd/href">https://medium.com/media/969c5c0a25aa6ab66cb6e83069b510dd/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/086b96d49376a10c1017ff78e5ca892d/href">https://medium.com/media/086b96d49376a10c1017ff78e5ca892d/href</a></iframe><p>This is the final result</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Ft0xk4&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Ft0xk4&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Ft0xk4%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/95b088ae7f7a840ade18c98c40759b63/href">https://medium.com/media/95b088ae7f7a840ade18c98c40759b63/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45b68fa22523" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>