<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Gabriel Penteado</title>
    <description>The latest articles on Forem by Gabriel Penteado (@gabrielpenteado).</description>
    <link>https://forem.com/gabrielpenteado</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F710732%2F9e22e9fd-9d1d-4c09-bb40-76642bb8d542.png</url>
      <title>Forem: Gabriel Penteado</title>
      <link>https://forem.com/gabrielpenteado</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/gabrielpenteado"/>
    <language>en</language>
    <item>
      <title>A Dentist's Code: My move to Software Development</title>
      <dc:creator>Gabriel Penteado</dc:creator>
      <pubDate>Fri, 07 Jun 2024 17:23:15 +0000</pubDate>
      <link>https://forem.com/gabrielpenteado/a-dentists-code-my-move-to-software-development-50gj</link>
      <guid>https://forem.com/gabrielpenteado/a-dentists-code-my-move-to-software-development-50gj</guid>
      <description>&lt;p&gt;Hello everyone, I want to share a personal journey that transformed my life in ways I never imagined. My professional background is in dentistry. I spent years mastering the art and science of dental care, but I always had a persistent interest in technology simmering beneath the surface. This fascination inspired me to take a bold step and venture into the world of software development.&lt;/p&gt;

&lt;p&gt;Transitioning from dentistry to software development was definitely a challenge for me. It involved countless hours of self-study, facing a steep learning curve, and often feeling like a beginner all over again. Even though skills like precision, problem-solving, and attention to detail that I learned during dental practice came in handy, I had to master a whole new set of tools and technologies.&lt;/p&gt;

&lt;p&gt;Our passion for something gives us the strength to overcome obstacles in a rewarding manner. When we are deeply committed to a task, even the most difficult challenges become surmountable. My dedication to coding and creativity has been my driving force during tough times.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fluadtzgl4ox1t469k6qx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fluadtzgl4ox1t469k6qx.png" alt="Tech Dental Office" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One of the most rewarding projects I have worked on is called 'Dental Procs'.  It is a tool made specifically for dentists. This project demonstrates the possibility of combining my two experiences in life (Health Dentistry and Software Engineering) to make something very useful.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dental Procs&lt;/strong&gt; is a specialized application designed for dentists to monitor the most performed procedures in their clinics and track performance trends over time. The app permits dentists to create new procedures, associating them with specific days of the week, and provides a comprehensive chart that offers an overview of procedure frequency.&lt;/p&gt;

&lt;p&gt;Dental Procs is built using a modern tech stack:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Frontend (Web): React, Vite, TypeScript, TailwindCSS, RadixUI&lt;/li&gt;
&lt;li&gt;Frontend (Mobile): React-Native&lt;/li&gt;
&lt;li&gt;Backend: Node.js, Fastify, Prisma, Zod&lt;/li&gt;
&lt;li&gt;Database: MySQL&lt;/li&gt;
&lt;li&gt;Charts and Analytics: ApexCharts&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpd3246fb3qh5t69jy35p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpd3246fb3qh5t69jy35p.png" alt="Dental Procs App" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This project not only bridges my past and present careers but also demonstrates the importance of pursuing your interests.. Each challenge faced and overcome during this journey has led to a product that I am incredibly proud of and excited to share with the dental community.&lt;/p&gt;

&lt;p&gt;You can find the source code &lt;a href="https://github.com/gabrielpenteado/dentalprocs" rel="noopener noreferrer"&gt;here&lt;/a&gt;, watch a &lt;a href="https://www.youtube.com/watch?v=0X3PRdZceBo" rel="noopener noreferrer"&gt;video&lt;/a&gt; presentation, and also try it on the &lt;a href="https://dentalprocs.onrender.com" rel="noopener noreferrer"&gt;website&lt;/a&gt;. Furthermore, feel free to visit my &lt;a href="https://gabrielpenteado.pages.dev/" rel="noopener noreferrer"&gt;&lt;strong&gt;personal website&lt;/strong&gt;&lt;/a&gt; to discover more about my work.&lt;/p&gt;




&lt;p&gt;To anyone considering a major career shift, I encourage you to embrace the difficulties and trust in your passion. The road may be tough, but the reward at the end makes it all worthwhile.&lt;/p&gt;

&lt;p&gt;Thank you for reading my story.&lt;/p&gt;

</description>
      <category>careerchange</category>
      <category>dentisttodev</category>
      <category>softwaredevelopment</category>
      <category>healthtotech</category>
    </item>
    <item>
      <title>Dockerize a React App - with Nginx</title>
      <dc:creator>Gabriel Penteado</dc:creator>
      <pubDate>Fri, 19 Jan 2024 19:08:30 +0000</pubDate>
      <link>https://forem.com/gabrielpenteado/dockerize-a-react-app-with-nginx-12aa</link>
      <guid>https://forem.com/gabrielpenteado/dockerize-a-react-app-with-nginx-12aa</guid>
      <description>&lt;h3&gt;
  
  
  What is Docker?
&lt;/h3&gt;

&lt;p&gt;Docker is a software platform that allows you to build, test, and deploy applications quickly. It enables users to group applications and their dependencies in isolated environments called containers. This makes it easy to design and shape containers with minimal instructions. Docker containers are lightweight and efficient, working independently to prevent interference between applications. Dockerizing your React application can provide many benefits, including a consistent development environment, easy deployment, isolated dependencies, and faster builds.&lt;/p&gt;

&lt;h3&gt;
  
  
  Dockerfile
&lt;/h3&gt;

&lt;p&gt;To build an image of your application, you need to specify instructions for the same in a Dockerfile. This instructions will be executed one after the other.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1qu1vaars6lr77921mx0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1qu1vaars6lr77921mx0.png" alt="dockerfile" width="631" height="521"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The instructions sequence from top to bottom is to use a specific Node image, copy all files from the React App to a temporary folder, install all dependencies from package.json, execute the build, move all files from the ‘dist’ folder created to the ‘app’ folder, remove the temporary folder, and expose port 8080.&lt;/p&gt;

&lt;p&gt;To build the image:&lt;br&gt;
&lt;code&gt;docker build -t react-image .&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;-t&lt;/strong&gt; option specifies the name for the image, and the dot at the end indicates the location of the Dockerfile; in this case, the root folder.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;.dockerignore&lt;/strong&gt; &lt;em&gt;is a configuration file that describes files and directories that you want to exclude when building a Docker image. E.g. /node_modules&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Container
&lt;/h3&gt;

&lt;p&gt;To create a container from the image run the command:&lt;br&gt;
&lt;code&gt;docker run -it -d --name react-container -p 8080:8080 -v react-volume:/app react-image&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-d&lt;/code&gt; runs the container in the background, not display the running process on your terminal, this is called &lt;em&gt;detached mode&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-it&lt;/code&gt; runs the container in interactive mode; allows you to interact with the container through the command line.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--name&lt;/code&gt; specifies a name for the container.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-p&lt;/code&gt; maps a host port to a container port.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-v&lt;/code&gt; mounts a host volume inside the container. In this example we create a volume named react-volume inside the &lt;em&gt;/app&lt;/em&gt; folder.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;react-image&lt;/em&gt; is the name of the image we created.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Nginx
&lt;/h3&gt;

&lt;p&gt;Nginx is a open-source web server and reverse proxy server. It is used to serve a React application with Docker in a production environment.&lt;/p&gt;

&lt;p&gt;To separate Dockerfile images, create a &lt;em&gt;nginx&lt;/em&gt; folder with two files: a &lt;em&gt;Dockerfile&lt;/em&gt; and &lt;em&gt;nginx.conf&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fau8qu864fzwdynabzpx7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fau8qu864fzwdynabzpx7.png" alt="nginx config" width="519" height="523"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;ningx.conf&lt;/em&gt; is a file to modify the default configuration of the nginx image. With these commands we specify to nginx listen on &lt;em&gt;port 80&lt;/em&gt; and when a client access the root (“/”) of the application, look in the &lt;em&gt;root&lt;/em&gt; of the image container for the &lt;em&gt;/app&lt;/em&gt; folder and then find the &lt;em&gt;index.html&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Ningx Dockerfile will have two instructions:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6fx1tpiuzgos9cnzuo9p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6fx1tpiuzgos9cnzuo9p.png" alt="nginx dockerfile" width="708" height="513"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;From an Nginx image, remove the &lt;em&gt;default.conf&lt;/em&gt; file, and copy the &lt;em&gt;nginx.conf&lt;/em&gt; file to its place, in the same path.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To build the image:&lt;br&gt;
&lt;code&gt;docker build -t nginx-react&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And run the container:&lt;br&gt;
&lt;code&gt;docker run -d -it --name nginx-react -p 80:80 --volumes-from react-container nginx-react&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The only new command here is &lt;code&gt;--volumes-from&lt;/code&gt; , which will make any volumes defined in the react-container available in the nginx container. Now, nginx-container have access to all files created after the build on the react-container.&lt;/p&gt;

&lt;p&gt;Finally, the React project is running in a Docker container and can be accessed through the browser at localhost:80 or just locahost because 80 is the default port.&lt;/p&gt;




&lt;h3&gt;
  
  
  Docker Compose
&lt;/h3&gt;

&lt;p&gt;Docker Compose is a tool for configuring and operating Docker applications that consist of multiple containers. By utilizing a YAML or YML file, you can set up the services required for your application. Then, with a single command, you create and start all the services from your configuration.&lt;/p&gt;

&lt;p&gt;Create a docker-compose.yml file:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwexqxokvgssk31gplx6x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwexqxokvgssk31gplx6x.png" alt="docker compose" width="775" height="540"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The docker-compose file have all instructions for the containers (&lt;em&gt;app-dc&lt;/em&gt; ; &lt;em&gt;nginx-dc&lt;/em&gt;) and it will create and start them with a single command:&lt;br&gt;
&lt;code&gt;docker compose up -d&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Developers can achieve a smooth and scalable deployment by using Docker containers to encapsulate the application and its dependencies, along with the powerful web server provided by Nginx.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Thank you for reading.&lt;br&gt;
If you liked this article shared it!&lt;br&gt;
I appreciate your feedback.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>docker</category>
      <category>nginx</category>
      <category>react</category>
      <category>devops</category>
    </item>
    <item>
      <title>An overview of Next Route Groups</title>
      <dc:creator>Gabriel Penteado</dc:creator>
      <pubDate>Tue, 16 Jan 2024 19:20:27 +0000</pubDate>
      <link>https://forem.com/gabrielpenteado/an-overview-of-next-route-groups-1j6g</link>
      <guid>https://forem.com/gabrielpenteado/an-overview-of-next-route-groups-1j6g</guid>
      <description>&lt;p&gt;&lt;strong&gt;Next Route Groups&lt;/strong&gt; are a way to organize routes in the app directory without changing the URL paths. By enclosing a folder name in parentheses, you can create a Route Group that helps keep related routes together. This allows for better organization and management of routes within the app.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdunsbgryriejjbeapqi1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdunsbgryriejjbeapqi1.jpg" alt="next-route-groups"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example, &lt;code&gt;(admin-routes) (auth-routes) (client-routes)&lt;/code&gt;&lt;br&gt;
 are route groups. they are grouped together for better organization, without altering URL structure.&lt;/p&gt;

&lt;p&gt;The URL path to the unauthorized page will be only &lt;code&gt;/unauthorized&lt;/code&gt; .&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Next Route Groups&lt;/strong&gt; enables you to organize your content logically, create nested layouts, and maintain a clean URL structure.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Thank you for reading.&lt;br&gt;
If you liked this article shared it!&lt;br&gt;
I appreciate your feedback.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>nextroutes</category>
      <category>react</category>
      <category>routes</category>
    </item>
    <item>
      <title>How to create a Dialog component with RadixUI and TailwindCSS</title>
      <dc:creator>Gabriel Penteado</dc:creator>
      <pubDate>Wed, 10 Jan 2024 16:37:25 +0000</pubDate>
      <link>https://forem.com/gabrielpenteado/how-to-create-a-dialog-component-with-radixui-and-tailwindcss-2md0</link>
      <guid>https://forem.com/gabrielpenteado/how-to-create-a-dialog-component-with-radixui-and-tailwindcss-2md0</guid>
      <description>&lt;h3&gt;
  
  
  Why use RadixUI?
&lt;/h3&gt;

&lt;p&gt;RadixUI is an open-source component library used to build friendly and accessible design systems and web applications. These components are unstyled and can be customized to user preferences.&lt;/p&gt;

&lt;p&gt;RadixUI offers a wide range of UI components, including buttons, forms, modals, menus, tooltips, and more, focusing on simplicity, performance, and accessibility.&lt;/p&gt;




&lt;h4&gt;
  
  
  Getting started…
&lt;/h4&gt;

&lt;p&gt;In this tutorial we are going to create a RadixUI modal dialog component which focus is automatically trapped, works in an uncontrolled way by default but can also be controlled . We are going to use TailwindCSS to style it.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You can use npm or yarn to install the package, here we use npm:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;npm install @radix-ui/react-dialog&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Import the Dialog component:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frz99w8bw3lubrmbntbhw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frz99w8bw3lubrmbntbhw.png" alt="import"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Let’s assume that TailwindCSS is already installed in the project.&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a dialog modal as the code below:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdda2crwg4qsupxki5ubx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdda2crwg4qsupxki5ubx.png" alt="dialog-code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;lt; Dialog.Root&amp;gt;&lt;/strong&gt; contains all the parts of a dialog.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;lt; Dialog.Trigger &amp;gt;&lt;/strong&gt; component is used to trigger the opening of the modal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;lt; Dialog.Portal &amp;gt;&lt;/strong&gt; component portals your overlay and content parts into the body.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;lt; Dialog.Close &amp;gt;&lt;/strong&gt; component is used to close the modal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;lt; Dialog.Overlay &amp;gt;&lt;/strong&gt; component creates a overlay behind the modal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;lt; Dialog.Title &amp;gt;&lt;/strong&gt; an accessible title to be announced when the dialog is opened.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&amp;lt; Dialog.Content &amp;gt;&lt;/strong&gt; contains content to be rendered in the open dialog.&lt;/p&gt;




&lt;p&gt;The Dialog component created will look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9vh77fgklaxtcr4tqrkz.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9vh77fgklaxtcr4tqrkz.jpg" alt="dialog-component"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;RadixUI simplifies the development process while ensuring accessibility and performance.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Thank you for reading.&lt;br&gt;
If you liked this article shared it!&lt;br&gt;
I appreciate your feedback.&lt;/strong&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Context API : Share state across components easily</title>
      <dc:creator>Gabriel Penteado</dc:creator>
      <pubDate>Tue, 09 Jan 2024 17:57:00 +0000</pubDate>
      <link>https://forem.com/gabrielpenteado/context-api-share-state-across-components-easily-5037</link>
      <guid>https://forem.com/gabrielpenteado/context-api-share-state-across-components-easily-5037</guid>
      <description>&lt;p&gt;In this post I will show you how React Context API is great to pass data that can be used in any component in your application.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;What is Context API ?&lt;/strong&gt;&lt;br&gt;
First, with&lt;u&gt; Vite&lt;/u&gt;, we created a TypeScript React application. In this example, we will share across all React applications, the state &lt;code&gt;user&lt;/code&gt; and a function &lt;code&gt;handleCreateUser&lt;/code&gt; to create a new user when a new data is received from the form.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Creating our context file &lt;strong&gt;userDataContext.tsx&lt;/strong&gt; in the &lt;em&gt;&lt;strong&gt;src&lt;/strong&gt;&lt;/em&gt; folder &lt;code&gt;src/context/userDataContext.tsx&lt;/code&gt; as below:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SDkDGxlp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tdus1fcxd384cuz9dqdg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SDkDGxlp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tdus1fcxd384cuz9dqdg.png" alt="context" width="599" height="792"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Import the &lt;code&gt;createContext&lt;/code&gt; from “react”;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Define an &lt;code&gt;interface&lt;/code&gt; for the user that will be created and an &lt;code&gt;interface&lt;/code&gt; for the context.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create context &lt;code&gt;UserContext&lt;/code&gt;. In TypeScript we have to type the elements that we will be exporting in this context, in this case, the state &lt;code&gt;user&lt;/code&gt; and a function to update this state &lt;code&gt;handleCreateUser&lt;/code&gt; also is necessary to type the createContext method with the correspondent interface.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next, create the &lt;em&gt;Provider&lt;/em&gt; that will share the context elements with all application. Using the function &lt;code&gt;UserProvider&lt;/code&gt; with one parameter &lt;code&gt;children&lt;/code&gt; (children will be any child components that we want to share this context) and &lt;em&gt;return&lt;/em&gt; this children wrapped by &lt;code&gt;&amp;lt;UserContext.Provider&amp;gt;&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We pass the two context elements through an object in the Provider &lt;code&gt;value&lt;/code&gt; prop just like that &lt;code&gt;value={{user, handleCreateUser}}&lt;/code&gt; . In TypeScript we have to type these elements and also type the parameter element that the Provider is receiving, in this case, &lt;em&gt;children&lt;/em&gt; as a &lt;em&gt;JSX.Element&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Finally, export our &lt;strong&gt;Context&lt;/strong&gt; and &lt;strong&gt;Provider&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;ul&gt;
&lt;li&gt;In the &lt;strong&gt;main.tsx&lt;/strong&gt; , we import the Provider and wrap our &lt;code&gt;&amp;lt;App /&amp;gt;&lt;/code&gt; with it as the image below:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9415fSHr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wh9nh5hi7ht7vlnnlwqs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9415fSHr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wh9nh5hi7ht7vlnnlwqs.png" alt="provider" width="662" height="352"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we have access to the context elements we created in our entire application!&lt;/p&gt;




&lt;ul&gt;
&lt;li&gt;Let’s use our context in the &lt;strong&gt;form.tsx&lt;/strong&gt; component. To use it we have to import the context and the &lt;em&gt;useContext&lt;/em&gt; hook from ‘react’.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iH6B6apr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9bf64a0mcgzod5oonbno.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iH6B6apr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9bf64a0mcgzod5oonbno.png" alt="useContext" width="517" height="161"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;useContext&lt;/em&gt; hook take the &lt;em&gt;UserContext&lt;/em&gt; as parameter and it is assign to a variable, in our exampleconst &lt;code&gt;context = useContext(UserContext)&lt;/code&gt; . This variable now is a object with our context elements &lt;code&gt;context.user&lt;/code&gt; and &lt;code&gt;context.handleCreateUser&lt;/code&gt; . The &lt;strong&gt;destructuring&lt;/strong&gt; assignment can be used too.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WTZd4dHV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v6wtedxh6gm6fpcukzgk.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WTZd4dHV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v6wtedxh6gm6fpcukzgk.jpg" alt="contextobj" width="531" height="77"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To create a new user we use the &lt;code&gt;handleCreateUser&lt;/code&gt; function from the context and pass it to the onSubmit event (as we define in context, this function receive one parameter &lt;em&gt;newuser&lt;/em&gt;). This way we create a new user and at same time we have access to the &lt;code&gt;user&lt;/code&gt; created from any component in our application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--D01bOoeQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ggoxqdmuk2f5mfc056xd.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--D01bOoeQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ggoxqdmuk2f5mfc056xd.jpg" alt="onsubmit" width="402" height="204"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope this guide gave you a better understanding of how to use React context API.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Thank you for reading.&lt;br&gt;
If you liked this article shared it!&lt;br&gt;
I appreciate your feedback.&lt;/strong&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>CSS Grid is a powerful tool to create layouts</title>
      <dc:creator>Gabriel Penteado</dc:creator>
      <pubDate>Fri, 05 Jan 2024 18:31:52 +0000</pubDate>
      <link>https://forem.com/gabrielpenteado/css-grid-is-a-powerful-tool-to-create-layouts-2o75</link>
      <guid>https://forem.com/gabrielpenteado/css-grid-is-a-powerful-tool-to-create-layouts-2o75</guid>
      <description>&lt;p&gt;In this post I will show you how you can make entire interfaces with a property of the CSS Grid.&lt;/p&gt;




&lt;h3&gt;
  
  
  CSS Grid Terminology
&lt;/h3&gt;

&lt;p&gt;First let's take a look quickly about CSS Grid terminology.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Grid Container&lt;/strong&gt; : The element on which grid is applied. The grid container is the parent of grid items.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Grid Item&lt;/strong&gt; : All directly nested elements of a grid container.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Grid Cell&lt;/strong&gt; : Every column in every row is a grid cell.CSS Grid can handle columns and rows, it is a 2-dimensional system.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  The Grid container property
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;grid-template-areas:&lt;/code&gt; With this property we define the names of the grid areas and reference them with the &lt;code&gt;grid-area&lt;/code&gt; property.&lt;/p&gt;

&lt;h4&gt;
  
  
  The Grid item property
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;grid-area:&lt;/code&gt; With this property you give a name to an item so that it can be referenced in the &lt;code&gt;grid-template-areas&lt;/code&gt; template.&lt;/p&gt;




&lt;h3&gt;
  
  
  Creating a template.
&lt;/h3&gt;

&lt;p&gt;In the body of the HTML file, we have a &lt;code&gt;div&lt;/code&gt; element with &lt;code&gt;class&lt;/code&gt; container. This is the parent element.&lt;br&gt;
Inside of the container we created four children elements &lt;code&gt;(header, section, aside and footer)&lt;/code&gt; each with &lt;code&gt;class&lt;/code&gt; grid-item.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1im06begna85t01x35p1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1im06begna85t01x35p1.jpg" alt="html"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With the CSS file we set layout with Grid.&lt;br&gt;
First, we define the &lt;code&gt;div&lt;/code&gt; with &lt;code&gt;class&lt;/code&gt; container as a grid container.&lt;br&gt;
After, using the property &lt;code&gt;grid-template-areas&lt;/code&gt; we make the grid template by referencing the names of each &lt;code&gt;grid-area&lt;/code&gt; property.&lt;br&gt;
Repeating the name of a grid-area causes the content to span those cells. A period &lt;code&gt;(.)&lt;/code&gt; makes a empty grid cell. And &lt;code&gt;none&lt;/code&gt; signifies no grid areas are defined.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fosmq5a86ofaaany9059k.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fosmq5a86ofaaany9059k.jpg" alt="css"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is a template with four columns and four rows.&lt;br&gt;
The &lt;code&gt;header&lt;/code&gt; spans all four columns in the first row.&lt;br&gt;
The &lt;code&gt;footer&lt;/code&gt; spans all four columns in the last row.&lt;br&gt;
The &lt;code&gt;main&lt;/code&gt; spans the first three columns in the second and third rows.&lt;br&gt;
And the &lt;code&gt;aside&lt;/code&gt; spans the last column of lines two and three.&lt;/p&gt;

&lt;p&gt;We also define a &lt;code&gt;gap: 5px&lt;/code&gt;; and the &lt;code&gt;height: 100vh&lt;/code&gt;;&lt;br&gt;
The result is shown in the figure below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhwhcwcpek2xh5vz2ctpu.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhwhcwcpek2xh5vz2ctpu.jpg" alt="layout"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Its possible to change the size of each grid-item with the properties of the grid container: &lt;code&gt;grid-template-columns&lt;/code&gt; and &lt;code&gt;grid-template-rows&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The CSS grid is a powerful tool to create entire layouts in a simple and effective way.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Thank you for reading.&lt;br&gt;
If you liked this article shared it!&lt;br&gt;
I appreciate your feedback.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>cssgrid</category>
      <category>layout</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
