<?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: Zuhalcode</title>
    <description>The latest articles on DEV Community by Zuhalcode (@zuhalcode).</description>
    <link>https://dev.to/zuhalcode</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%2F2063250%2F463f4e9d-d6f1-40f8-b3ff-c1d83d033203.jpg</url>
      <title>DEV Community: Zuhalcode</title>
      <link>https://dev.to/zuhalcode</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/zuhalcode"/>
    <language>en</language>
    <item>
      <title>Effective Ways to Integrate SVG into NextJS App</title>
      <dc:creator>Zuhalcode</dc:creator>
      <pubDate>Thu, 12 Sep 2024 12:50:56 +0000</pubDate>
      <link>https://dev.to/zuhalcode/effective-ways-to-integrate-svg-into-nextjs-app-43e3</link>
      <guid>https://dev.to/zuhalcode/effective-ways-to-integrate-svg-into-nextjs-app-43e3</guid>
      <description>&lt;p&gt;SVG (Scalable Vector Graphics) is a highly useful image format in web development due to its ability to maintain image quality across various sizes. However, integrating SVGs into a Next.js application is often considered complicated. This article provides a practical guide on how to effectively integrate SVGs into your Next.js project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Building the Folder Structure
&lt;/h2&gt;

&lt;p&gt;To integrate SVGs into your Next.js application, create an assets folder within src. Place your SVG files inside this folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;src/
|── assets/
│   └── logo.svg
└── pages/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Configuring Webpack for SVGs
&lt;/h2&gt;

&lt;p&gt;To use SVGs as React components, you need to configure Webpack and install &lt;code&gt;@svgr/webpack&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Install &lt;code&gt;@svgr/webpack&lt;/code&gt; with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install @svgr/webpack --save-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open the &lt;code&gt;next.config.js&lt;/code&gt; file in the root of your project.&lt;/p&gt;

&lt;p&gt;Add the following configuration to integrate &lt;code&gt;@svgr/webpack&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;// next.config.js
module.exports = {
  webpack(config) {
    config.module.rules.push({
      test: /\.svg$/,
      use: ['@svgr/webpack'],
    });

    return config;
  },
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using SVGs in React Components
&lt;/h2&gt;

&lt;p&gt;Import the SVG file that you placed in the &lt;code&gt;src/assets&lt;/code&gt; folder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Logo from '@/src/assets/logo.svg';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use the SVG in your React component as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Logo from '../src/assets/logo.svg';

export default function HomePage() {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;Selamat Datang di Website Kami!&amp;lt;/h1&amp;gt;
      &amp;lt;Logo width={100} height={100} /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;By following these steps, you can easily integrate SVGs into your Next.js application, enhancing both the design and performance of your project. An organized folder structure and proper configuration will help you make the most of SVGs.&lt;/p&gt;

</description>
      <category>react</category>
      <category>tutorial</category>
      <category>programming</category>
      <category>nextjs</category>
    </item>
  </channel>
</rss>
