<?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>DEV Community: Abdeldjalil Hachimi</title>
    <description>The latest articles on DEV Community by Abdeldjalil Hachimi (@abdeldjalilhachimi).</description>
    <link>https://dev.to/abdeldjalilhachimi</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%2F416193%2F30733dcc-77e0-46b3-b4eb-e3c9ed6ffae8.png</url>
      <title>DEV Community: Abdeldjalil Hachimi</title>
      <link>https://dev.to/abdeldjalilhachimi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abdeldjalilhachimi"/>
    <language>en</language>
    <item>
      <title>Normalized User Interface (UI) for Frontend Developers Part 1</title>
      <dc:creator>Abdeldjalil Hachimi</dc:creator>
      <pubDate>Sun, 01 Sep 2024 13:20:20 +0000</pubDate>
      <link>https://dev.to/abdeldjalilhachimi/normalized-or-normal-ui-part-1-1e4</link>
      <guid>https://dev.to/abdeldjalilhachimi/normalized-or-normal-ui-part-1-1e4</guid>
      <description>&lt;h1&gt;
  
  
  Normalized User Interface (UI) Design for Frontend Developers
&lt;/h1&gt;

&lt;p&gt;As front-end web developers, it's important to understand the concept of normalized user interface (UI) design. This approach involves &lt;strong&gt;splitting software workflows across different screens&lt;/strong&gt;, ensuring each screen focuses on a particular task. This simplifies the user experience by reducing confusion and making interactions more intuitive.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Concepts: Workflows, Screens, and Frames
&lt;/h2&gt;

&lt;p&gt;When thinking about UI design, we often consider features, but for normalized UI, it's more useful to focus on:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Screens&lt;/strong&gt;: These are pages or modals in a web application.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Frames&lt;/strong&gt;: These are sets of UI elements that can be accessed simultaneously at a specific moment. They represent a subset of a screen's potential content.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Workflows&lt;/strong&gt;: These are sequences of actions that users take, which might involve moving between different frames or screens.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Example: Link Navigation
&lt;/h2&gt;

&lt;p&gt;Let's consider an example using links to better illustrate these concepts:&lt;/p&gt;

&lt;h3&gt;
  
  
  Workflow with Frames
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Screen 1&lt;/strong&gt;: The user starts on the main page, where they see a list of frequently asked questions (FAQs). Each FAQ is collapsed initially, displaying only the question. This state is a &lt;strong&gt;frame&lt;/strong&gt; because it represents a subset of content on the screen.&lt;/li&gt;
&lt;/ol&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%2Fflqt1skvtbdg7s5i5zxo.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%2Fflqt1skvtbdg7s5i5zxo.png" alt="Main Page - Collapsed FAQs" width="596" height="816"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Action&lt;/strong&gt;: The user clicks on a question. This action reveals the answer within the same screen, transitioning to a new &lt;strong&gt;frame&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&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%2F05xt3v7030dlp2w9lxok.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%2F05xt3v7030dlp2w9lxok.png" alt="FAQ Open - Showing Answer" width="596" height="734"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Action&lt;/strong&gt;: The user clicks again to hide the answer, returning to the initial frame.&lt;/li&gt;
&lt;/ol&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%2Fe6s7gawm16e0co3y9sbm.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%2Fe6s7gawm16e0co3y9sbm.png" alt="FAQ Closed - Hiding Answer" width="596" height="692"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Workflow with Screens
&lt;/h3&gt;

&lt;p&gt;Now, consider a different design approach using screens:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Screen 1&lt;/strong&gt;: The user starts on the main page with a list of questions, but instead of expanding within the same screen, clicking a question navigates to a separate page that displays the answer.&lt;/li&gt;
&lt;/ol&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%2Fflqt1skvtbdg7s5i5zxo.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%2Fflqt1skvtbdg7s5i5zxo.png" alt="Main Page with Question Links" width="596" height="816"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Action&lt;/strong&gt;: Clicking a question takes the user to a new screen (or modal), dedicated to showing the full answer.&lt;/li&gt;
&lt;/ol&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%2F1sp2rzuosr4m3njxi5r4.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%2F1sp2rzuosr4m3njxi5r4.png" alt="Question Page" width="598" height="594"&gt;&lt;/a&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%2Fnpeyeto6dusq2swcfz40.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%2Fnpeyeto6dusq2swcfz40.png" alt="Answer Page" width="598" height="594"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Workflow Diagrams
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Frame-Based Workflow Diagram&lt;/strong&gt;: Here, each action changes the frame without navigating away from the screen.&lt;/li&gt;
&lt;/ul&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%2Ft3h11kqa5rutdnbv8k3f.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%2Ft3h11kqa5rutdnbv8k3f.png" alt="Workflow Diagram with Frames" width="800" height="247"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Screen-Based Workflow Diagram&lt;/strong&gt;: In this design, each action navigates to a new screen.&lt;/li&gt;
&lt;/ul&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%2Fsns1vbzoufwdrbdngo5l.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%2Fsns1vbzoufwdrbdngo5l.png" alt="Workflow Diagram with Screens" width="772" height="382"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Using normalized UI design principles and visualizing them through workflow diagrams can make the interface more intuitive and user-friendly. Whether you use frames within a single screen or navigate between screens, the goal is to simplify the user experience and reduce confusion. Stay tuned for more insights on Normal UI design!&lt;/p&gt;

</description>
      <category>development</category>
      <category>frontend</category>
      <category>css</category>
      <category>codepen</category>
    </item>
    <item>
      <title>From Redux Saga to React Query</title>
      <dc:creator>Abdeldjalil Hachimi</dc:creator>
      <pubDate>Thu, 24 Aug 2023 11:36:25 +0000</pubDate>
      <link>https://dev.to/abdeldjalilhachimi/from-redux-saga-to-react-query-3n90</link>
      <guid>https://dev.to/abdeldjalilhachimi/from-redux-saga-to-react-query-3n90</guid>
      <description>&lt;p&gt;Last time I was responsible for refactoring React app project that was built with Redux Saga, Honestly That sucked!&lt;/p&gt;

&lt;p&gt;Boilerplate code was everywhere, and the app complexity was very high.&lt;/p&gt;

&lt;p&gt;You had to handle errors, loadings, data... everything manually.&lt;/p&gt;

&lt;p&gt;Solutions like caching were also not available out of the box.&lt;/p&gt;

&lt;p&gt;What I have done I used React hooks and React context as well as the outstanding library #React Query&lt;/p&gt;

&lt;p&gt;It brought 4 benefits:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Less boilerplate code&lt;/li&gt;
&lt;li&gt;Easy to implement and understand&lt;/li&gt;
&lt;li&gt;Fetch, synchronize, update, and cache your remote data&lt;/li&gt;
&lt;li&gt;No need to put your remote data inside the global state&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you are building a React app with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Client-side rendering&lt;/li&gt;
&lt;li&gt;Lots of server data to handle&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Don't think more about it.&lt;/p&gt;

&lt;p&gt;You have to use React Query.&lt;/p&gt;

&lt;p&gt;It's a game-changer!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>redux</category>
      <category>reduxsaga</category>
    </item>
    <item>
      <title>Migration to TypeScript Advice</title>
      <dc:creator>Abdeldjalil Hachimi</dc:creator>
      <pubDate>Wed, 05 Jul 2023 17:30:10 +0000</pubDate>
      <link>https://dev.to/abdeldjalilhachimi/migration-to-typescript-advice-32e4</link>
      <guid>https://dev.to/abdeldjalilhachimi/migration-to-typescript-advice-32e4</guid>
      <description>&lt;ul&gt;
&lt;li&gt;&lt;p&gt;For large projects, it is recommended to adopt a gradual transition where TypeScript and JavaScript code will initially coexist. Only small projects can be migrated to TypeScript in one go.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The first step of this transition is to introduce TypeScript into the build chain process. This can be done by using the "allowJs" compiler option, which permits &lt;code&gt;.ts&lt;/code&gt; and &lt;code&gt;.tsx&lt;/code&gt; files to coexist with existing JavaScript files. As TypeScript will fall back to a type of "any" for a variable when it cannot infer the type from JavaScript files, it is recommended to disable "noImplicitAny" in your compiler options at the beginning of the migration.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The second step is to ensure that your JavaScript tests work alongside TypeScript files so that you can run tests as you convert each module. If you are using Jest, consider using ts-&lt;code&gt;jest&lt;/code&gt;, which allows you to test TypeScript projects with Jest.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The third step is to include type declarations for third-party libraries in your project. These declarations can be found either bundled or on DefinitelyTyped. You can search for them using &lt;a href="https://www.typescriptlang.org/dt/search"&gt;https://www.typescriptlang.org/dt/search&lt;/a&gt; and install them using&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save-dev @types/package-name or yarn add --dev @types/package-name.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The fourth step is to migrate module by module with a bottom-up approach, following your Dependency Graph starting with the leaves. The idea is to start converting Modules that do not depend on other Modules. To visualize the dependency graphs, you can use the &lt;code&gt;madge&lt;/code&gt; tool.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Good candidate modules for these initial conversions are utility functions and code related to external APIs or specifications. It is possible to automatically generate TypeScript type definitions from Swagger contracts, GraphQL or JSON schemas to be included in your project. as well as you can use website called &lt;a href="https://quicktype.io/"&gt;https://quicktype.io/&lt;/a&gt; to generate types and interfaces in order to user them in your &lt;code&gt;tsx&lt;/code&gt; or &lt;code&gt;ts&lt;/code&gt; file.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When there are no specifications or official schemas available, you can generate types from raw data, such as JSON returned by a server. However, it is recommended to generate types from specifications instead of data to avoid missing edge cases.&lt;/p&gt;

&lt;p&gt;During the migration, refrain from code refactoring and focus only on adding types to your modules.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The fifth step is to enable &lt;code&gt;"noImplicitAny"&lt;/code&gt; which will enforce that all types are known and defined, providing a better TypeScript experience for your project.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;During the migration, you can use the &lt;code&gt;@ts-check&lt;/code&gt; directive, which enables TypeScript type checking in a JavaScript file. This directive provides a loose version of type checking and can be initially used to identify issues in JavaScript files. When&lt;code&gt;@ts-check&lt;/code&gt; is included in a file, TypeScript will try to deduce definitions using JSDoc-style comments. However, consider using JSDoc annotations only at a very early stage of the migration.&lt;/p&gt;

&lt;p&gt;Consider keeping the default value of &lt;code&gt;noEmitOnError&lt;/code&gt; in your &lt;code&gt;tsconfig.json&lt;/code&gt; as false. This will allow you to output JavaScript source code even if errors are reported.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Resource&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://github.com/gibbok/typescript-book#migration-to-typescript-advice"&gt;Link&lt;/a&gt;&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>javascript</category>
      <category>tsjs</category>
      <category>migratefromjstot</category>
    </item>
    <item>
      <title>What are different between Normal Copy and Shallow Copy, Deep Copy in JavaScript Object</title>
      <dc:creator>Abdeldjalil Hachimi</dc:creator>
      <pubDate>Mon, 17 Apr 2023 22:57:51 +0000</pubDate>
      <link>https://dev.to/abdeldjalilhachimi/what-are-different-between-normal-copy-and-shallow-copy-deep-copy-in-javascript-object-1k45</link>
      <guid>https://dev.to/abdeldjalilhachimi/what-are-different-between-normal-copy-and-shallow-copy-deep-copy-in-javascript-object-1k45</guid>
      <description>&lt;p&gt;Hello everyone, I hope you are doing great. &lt;/p&gt;

&lt;p&gt;today I would like to explain the different between &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Normal copy in JavaScript Object&lt;/li&gt;
&lt;li&gt;Shallow copy in JavaScript Object&lt;/li&gt;
&lt;li&gt;Deep copy in JavaScript Object&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;Note : In JavaScript objects  are passed and assigned by reference (more accurately the value of a reference)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;let's start first with  Normal copy in JavaScript Object&lt;/p&gt;

&lt;h2&gt;
  
  
  Normal copy in JavaScript Object
&lt;/h2&gt;

&lt;p&gt;in short, When you change the original object's properties, the copied object's properties will change too (and vice versa)&lt;/p&gt;

&lt;p&gt;let's make an example :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Normal copy  in Js Object

const person = {
  name: "Abdeldjalil",
  country: "Algeria"
};

const newPerson = person;

/*
Now if we make a change in
newPerson object
will directly change 
in preson Object 

*/

newPerson.country = "Canda"; // also updates person.country

console.log(newPerson); // {name: "Abdeldjalil", country: "Canda"}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Shallow copy in JavaScript Object
&lt;/h2&gt;

&lt;p&gt;in short, Top level properties will be unique for the original and the copied object. Nested properties will be shared across both objects though. Use the spread operator &lt;code&gt;...{}&lt;/code&gt; or &lt;code&gt;Object.assign()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;let's have an example for more understanding&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Shallow copy  in Js Object

const person = {
  name: "Abdeldjalil",
  country: "Algeria",
  job: {
    category: "web developement",
    profession: "Front-End Web Developer"
  }
};

const newPerson = { ...person };

/*

Now if we make a change in
Top level properties in newPerson object
will not  change 
in preson Object 
but if we make change in Nested Properties in this case 
Job property  will change 

*/

// top levele property
newPerson.name = "John Dev"; // will not updates person.name

// Nested  property
newPerson.job.profession = "Backend Devloper"; // also updates person.job.profession

console.log(newPerson); `// {name: "John Dev", country: "Algeria", job: Object} name: "Abdeldjalil" country: "Algeria" job: { category: "web developement" profession: "Backend Devloper"}}`

console.log(person); `// {name: "Abdeldjalil", country: "Algeria", job: Object} name: "Abdeldjalil" country: "Algeria" job: { category: "web developement" profession: "Backend Devloper"}}`


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Deep copy in JavaScript Object
&lt;/h2&gt;

&lt;p&gt;in short, All properties are unique for the original and the copied object, even nested properties. For a deep copy, serialize the object to JSON and parse it back to a JS object.&lt;/p&gt;

&lt;p&gt;let's make an example about it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Shallow copy  in Js Object

const person = {
  name: "Abdeldjalil",
  country: "Algeria",
  job: {
    category: "web developement",
    profession: "Front-End Web Developer"
  }
};

const newPerson = JSON.parse(JSON.stringify(person));

/*

Now if we make a change in
Top level properties in newPerson object
or even in nested  properties will not change 
in preson Object 

*/

// top levele property
newPerson.name = "Setiv Smith "; // will not updates person.job.profession

// Nested  property
newPerson.job.profession = "Fullstack Devloper"; // will not update  person.job.profession

console.log(newPerson); `// {name: "Setiv Smith ", country: "Algeria", job: Object} name: "Setiv Smith " country: "Algeria" job: { category: "web developement" profession: "Fullstack Devloper" }`

console.log(person); `// {name: "Abdeldjalil ", country: "Algeria", job: Object} name: "Setiv Smith " country: "Algeria" job: { category: "web developement" profession: "Front-End Web Developer" }`


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thank you for reading this Article and I am waiting  for your feedbacks&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to use Google Maps Places Autocomplete with React JS</title>
      <dc:creator>Abdeldjalil Hachimi</dc:creator>
      <pubDate>Thu, 13 Apr 2023 23:07:02 +0000</pubDate>
      <link>https://dev.to/abdeldjalilhachimi/how-to-use-google-maps-places-autocomplete-with-react-js-161j</link>
      <guid>https://dev.to/abdeldjalilhachimi/how-to-use-google-maps-places-autocomplete-with-react-js-161j</guid>
      <description>&lt;p&gt;Hello everyone, I hope you are doing.&lt;br&gt;
today I would like to explain how to use google maps places autocomplete without any libraries or npm's packages and headache 😂 so that let's get started &lt;/p&gt;

&lt;h2&gt;
  
  
  Setup and Installing React JS
&lt;/h2&gt;

&lt;p&gt;let's do it very quick just follow the steps I suppose you have some background how to do so &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&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%2Ffqfpg6x9min1q3bp5q9e.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%2Ffqfpg6x9min1q3bp5q9e.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&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%2Fo2os8v6bdpcnd4fw4udh.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%2Fo2os8v6bdpcnd4fw4udh.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3.&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%2Fflybvczf8aclgrrbudaa.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%2Fflybvczf8aclgrrbudaa.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4.&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%2Fi2j78ye6bh60qiaz14py.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%2Fi2j78ye6bh60qiaz14py.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;5.&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%2Fxz9jke8zfk54o5g9duha.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%2Fxz9jke8zfk54o5g9duha.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;6.&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%2Fq5czhecjw44yuzfp1jyf.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%2Fq5czhecjw44yuzfp1jyf.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;7.&lt;br&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%2Fygm6mymuxc01cpjiao4m.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%2Fygm6mymuxc01cpjiao4m.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;the first thing you have to do in index.html after setup the project is that&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8" /&amp;gt;
    &amp;lt;link rel="icon" type="image/svg+xml" href="/vite.svg" /&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0" /&amp;gt;
    &amp;lt;title&amp;gt; React js with Google Map AutoComplete &amp;lt;/title&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;div id="root"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;script type="module" src="/src/main.jsx"&amp;gt;&amp;lt;/script&amp;gt;

**    &amp;lt;script
      src="https://maps.googleapis.com/maps/api/js?key="your-api-key"&amp;amp;libraries=places&amp;amp;callback=initMap"
      async
    &amp;gt;&amp;lt;/script&amp;gt;**
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;after that create a component for Map using the library @react-google-maps/api &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import React, { useState, useCallback } from 'react'
import { GoogleMap, Marker, useJsApiLoader } from '@react-google-maps/api'


const mapStyle = { 
    height: '300px', 
    width: '100%'
 }



const Map = () =&amp;gt; {
    const DEFAULT_ZOOM = 5
    const { isLoaded } = useJsApiLoader({
        id: 'google-map-script',
        googleMapsApiKey: "your-api-key"
    })

    const [map, setMap] = React.useState(null)
    const [markerPosition, setMarkerPosition] = useState({
        lat: 28.0289837,
        lng: 1.6666663,
      })

    const [defaultLocation, setDefaultLocation] = useState({
        lat: 28.0289837,
        lng: 1.6666663,
      })

    const onLoad = useCallback((map)=&amp;gt; {
        const bounds = new window.google.maps.LatLngBounds({
            lat: 28.0289837,
            lng: 1.6666663,
          });
        map.fitBounds(bounds);
        setMap(map)
      }, [])

      const onUnmount = useCallback(() =&amp;gt;{
        setMap(null)
      }, [])


    const handelClickOnMap  = ()=&amp;gt; {

      }
  return (
    &amp;lt;div&amp;gt;
     {
        isLoaded ? (
        &amp;lt;GoogleMap
        onLoad={onLoad}
        center={defaultLocation}
        zoom={DEFAULT_ZOOM}
        mapContainerStyle={mapStyle}
        onClick={handelClickOnMap}
        onUnmount={onUnmount}
        &amp;gt;
           &amp;lt;Marker position={markerPosition} /&amp;gt;
        &amp;lt;/GoogleMap&amp;gt;
        ) : &amp;lt;&amp;gt;&amp;lt;/&amp;gt;
     }  
   &amp;lt;/div&amp;gt;
  )
}

export default Map


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;after that import Map component in App.jsx file &lt;br&gt;
and now let's create our input for search for places with autocomplete (suggestion places)&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

    import { useRef, useState } from 'react'
import MapView from './components/Map'


function App() {

  const inputRef = useRef()
  const inputStyle= {
    boxShadow: 'inset 0 0 10px #eee !important',
    border: '2px solid #eee',
    width: '456px',
    height: '40px',
    marginLeft: '16px',
    borderRadius: '20px',
    fontWeight: '300 !important',
    outline: 'none',
    padding: '10px 20px',
    marginBottom: '10px',
  }


  const autoComplete = new window.google.maps.places.Autocomplete(
    inputRef.current,
  )


  autoComplete.addListener('place_changed', () =&amp;gt; {
    const place = autoComplete.getPlace()
    if (!place.geometry || !place.geometry.location) {
      // User entered the name of a Place that was not suggested and
      // pressed the Enter key, or the Place Details request failed.
        alert("this location not available")
    }
    if (place.geometry.viewport || place.geometry.location) {
        // do something
        console.log(place.geometry.location)
    }
  })
  return (
    &amp;lt;div className="App"&amp;gt;
        &amp;lt;label &amp;gt;Location&amp;lt;/label&amp;gt;
        &amp;lt;input
          placeholder='type your location'
          ref={inputRef}
          style={inputStyle}
        /&amp;gt;
      &amp;lt;MapView/&amp;gt;
    &amp;lt;/div&amp;gt;
  )
}

export default App



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;and voila here it is the result 😁&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%2Ffzp53z50wc2e6jz3kl6m.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%2Ffzp53z50wc2e6jz3kl6m.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, Thank you for reading this post I will glad to hear your feedback.&lt;/p&gt;

&lt;h2&gt;
  
  
  Github repo for code source
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/abdeldjalilhachimi/react-google-map-autocomplete" rel="noopener noreferrer"&gt;https://github.com/abdeldjalilhachimi/react-google-map-autocomplete&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>googlemap</category>
      <category>javascript</category>
      <category>autocompelete</category>
    </item>
    <item>
      <title>How to use absolute Imports using React with Ts and Vite</title>
      <dc:creator>Abdeldjalil Hachimi</dc:creator>
      <pubDate>Fri, 04 Feb 2022 16:54:46 +0000</pubDate>
      <link>https://dev.to/abdeldjalilhachimi/how-to-avoid-long-path-import-using-react-with-ts-and-vite-4e2h</link>
      <guid>https://dev.to/abdeldjalilhachimi/how-to-avoid-long-path-import-using-react-with-ts-and-vite-4e2h</guid>
      <description>&lt;p&gt;today I am going to talk about How to use absolute Imports using React with Ts and Vite &lt;/p&gt;

&lt;p&gt;as you can see here I am using &lt;code&gt;...&lt;/code&gt; to find the path of components in order to use them, it looks fine since I do not have deep path.&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%2F8psbciavypg4kew6ur3c.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%2F8psbciavypg4kew6ur3c.png" alt="Image description" width="800" height="677"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;to sum up in order to avoid it you can easily use this in your&lt;br&gt;
 &lt;code&gt;tsconfig.json&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"compilerOptions": {
    "baseUrl": "./src",
    "paths": {
      "~/*": ["./*"]
    },
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fbphpoxrpnb0ckcnpc5ik.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%2Fbphpoxrpnb0ckcnpc5ik.png" alt="Image description" width="650" height="516"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and after that go to &lt;code&gt;vite.config.ts&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  resolve: {
    alias: {
      '~': path.resolve(__dirname, 'src'),
    },
  },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fq4d7sk8ndpgp2m03mw50.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%2Fq4d7sk8ndpgp2m03mw50.png" alt="Image description" width="800" height="734"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and it's done &lt;/p&gt;

&lt;p&gt;Thanks for reading this article and if you have any suggestions you are welcome &lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>vite</category>
    </item>
  </channel>
</rss>
