<?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: Gereltuya Munkhzaya</title>
    <description>The latest articles on DEV Community by Gereltuya Munkhzaya (@gereltuyamz).</description>
    <link>https://dev.to/gereltuyamz</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%2F913694%2Fb8a65d18-e427-4a62-9489-ee2d292f95cb.jpeg</url>
      <title>DEV Community: Gereltuya Munkhzaya</title>
      <link>https://dev.to/gereltuyamz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gereltuyamz"/>
    <language>en</language>
    <item>
      <title>When to use dangerouslySetInnerHTML in React?</title>
      <dc:creator>Gereltuya Munkhzaya</dc:creator>
      <pubDate>Fri, 29 Sep 2023 03:22:16 +0000</pubDate>
      <link>https://dev.to/gereltuyamz/when-to-use-dangerouslysetinnerhtml-in-react-3ol</link>
      <guid>https://dev.to/gereltuyamz/when-to-use-dangerouslysetinnerhtml-in-react-3ol</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Rendering HTML markup from rich text created in a WYSIWYG editor might be difficult. Because numerous pieces of logic are required to make things work as they should. This can be attributed to the fact that React uses a browser-independent system to manipulate the DOM elements, thus preventing direct interaction with the DOM. Things can be pretty much easier and faster with dangerouslySetInnerHTML.&lt;/p&gt;

&lt;p&gt;In this tutorial, we'll see how to use dangerouslySetInnerHTML in a React application.&lt;/p&gt;

&lt;p&gt;Step we'll cover:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What is dangerouslySetInnerHTML?&lt;/li&gt;
&lt;li&gt;When to use dangerouslySetInnerHTML?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What is dangerouslySetInnerHTML?
&lt;/h2&gt;

&lt;p&gt;React dangerouslySetInnerHTML is an HTML property that makes it easy to programmatically set the HTML elements from an external source. It has replaced the innerHTML used in the browser DOM. dangerouslySetInnerHTML helps React know how to handle the HTML elements in a component where the contents are to be rendered.&lt;/p&gt;

&lt;h2&gt;
  
  
  When to use dangerouslySetInnerHTML?
&lt;/h2&gt;

&lt;p&gt;dangerouslySetInnerHTML is mostly used in any application where you need to render formatted text in a div element. Also, you can use it to render content exactly as you have formatted it. For instance, let's consider a blog application. The body of a blog is usually formatted with headers, paragrams, images, code blocks, etc.&lt;/p&gt;

&lt;p&gt;To render such contents in a React application, you'll need to manipulate the DOM to get the HTML elements in the contents and set them to an element using innerHTML. Because React does not allow direct interaction with the DOM, your content will end up not being displayed as it should. However, when dangerouslySetInnerHTML is applied, React recognizes the HTML tags and correctly renders them.&lt;/p&gt;

&lt;p&gt;Due to its vulnerability to cross-site scripting (XSS) attacks, dangerouslySetInnerHTML might constitute a major threat to your application, as the name suggests. However, DOMPurify has proven to be a highly effective tool in overcoming such difficulties. DOMPurify is a DOM-only XSS sanitizer for HTML for preventing XSS attacks by stripping out all dangerous HTML in content rendered in an application.&lt;/p&gt;

&lt;p&gt;For example, if users are permitted to insert HTML directly into a web page via a form field, hackers can embed malicious code into the application, causing the application to behave inappropriately or even resulting in data loss. &lt;/p&gt;

&lt;p&gt;In the above code snippet, we imported dompurify to sanitize the contents in the blog, react-bootstrap components to style the application, and the dummy JSON data we created. Then in the card, we looped through the blogs to access and render the data in the objects.&lt;/p&gt;

&lt;p&gt;For the Card title and Text, we added div elements and attached the dangerouslySetInnerHTML property to render the contents according to how they were formatted.&lt;/p&gt;

&lt;p&gt;To allow the div where the contents are rendered to have children, we passed in the --html key to dangerouslySetInnerHTML and wrapped the content to be rendered in the dompurify sanitize method.&lt;/p&gt;

</description>
      <category>webdev</category>
    </item>
    <item>
      <title>Static Assets</title>
      <dc:creator>Gereltuya Munkhzaya</dc:creator>
      <pubDate>Fri, 29 Sep 2023 02:46:24 +0000</pubDate>
      <link>https://dev.to/gereltuyamz/static-assets-3i6c</link>
      <guid>https://dev.to/gereltuyamz/static-assets-3i6c</guid>
      <description>&lt;p&gt;Traveling is an enriching experience that opens up new horizons, exposes us to different cultures, and creates memories that last a lifetime. However, traveling can also be stressful and overwhelming, especially if you don't plan and prepare adequately. In this blog article, we'll explore tips and tricks for a memorable journey and how to make the most of your travels.&lt;/p&gt;

&lt;p&gt;One of the most rewarding aspects of traveling is immersing yourself in the local culture and customs. This includes trying local cuisine, attending cultural events and festivals, and interacting with locals. Learning a few phrases in the local language can also go a long way in making connections and showing respect.&lt;/p&gt;

&lt;h2&gt;
  
  
  Research Your Destination
&lt;/h2&gt;

&lt;p&gt;Before embarking on your journey, take the time to research your destination. This includes understanding the local culture, customs, and laws, as well as identifying top attractions, restaurants, and accommodations. Doing so will help you navigate your destination with confidence and avoid any cultural faux pas.&lt;/p&gt;

&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. In hendrerit gravida rutrum quisque non tellus orci ac auctor. Mi ipsum faucibus vitae aliquet nec ullamcorper sit amet. Aenean euismod elementum nisi quis eleifend quam adipiscing vitae. Viverra adipiscing at in tellus.&lt;/p&gt;

&lt;h2&gt;
  
  
  Plan Your Itinerary
&lt;/h2&gt;

&lt;p&gt;While it's essential to leave room for spontaneity and unexpected adventures, having a rough itinerary can help you make the most of your time and budget. Identify the must-see sights and experiences and prioritize them according to your interests and preferences. This will help you avoid overscheduling and ensure that you have time to relax and enjoy your journey.&lt;/p&gt;

&lt;p&gt;Vitae sapien pellentesque habitant morbi tristique. Luctus venenatis lectus magna fringilla. Nec ullamcorper sit amet risus nullam eget felis. Tincidunt arcu non sodales neque sodales ut etiam sit amet.&lt;/p&gt;

</description>
      <category>programming</category>
    </item>
    <item>
      <title>Analytics</title>
      <dc:creator>Gereltuya Munkhzaya</dc:creator>
      <pubDate>Wed, 27 Sep 2023 05:14:53 +0000</pubDate>
      <link>https://dev.to/gereltuyamz/analytics-24ao</link>
      <guid>https://dev.to/gereltuyamz/analytics-24ao</guid>
      <description>&lt;p&gt;Next.js Speed Insights allows you to analyze and measure the performance of pages using different metrics.&lt;/p&gt;

&lt;p&gt;You can start collecting your Real Experience Score with zero-configuration on Vercel deployments.&lt;/p&gt;

&lt;p&gt;The rest of this documentation describes the built-in relayer Next.js Speed Insights uses.&lt;/p&gt;

&lt;p&gt;This function is fired when the final values for any of the metrics have finished calculating on the page. You can use to log any of the results to the console or send to a particular endpoint.&lt;/p&gt;

&lt;p&gt;The metric object returned to the function consists of a number of properties:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;id: Unique identifier for the metric in the context of the current page load&lt;/li&gt;
&lt;li&gt;name: Metric name&lt;/li&gt;
&lt;li&gt;startTime: First recorded timestamp of the performance entry in milliseconds (if applicable)&lt;/li&gt;
&lt;li&gt;value: Value, or duration in milliseconds, of the performance entry&lt;/li&gt;
&lt;li&gt;label: Type of metric (web-vital or custom)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are two types of metrics that are tracked:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Web Vitals&lt;/li&gt;
&lt;li&gt;Custom metrics&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
    </item>
    <item>
      <title>Lazy Loading</title>
      <dc:creator>Gereltuya Munkhzaya</dc:creator>
      <pubDate>Wed, 27 Sep 2023 05:14:03 +0000</pubDate>
      <link>https://dev.to/gereltuyamz/lazy-loading-4c17</link>
      <guid>https://dev.to/gereltuyamz/lazy-loading-4c17</guid>
      <description>&lt;p&gt;Lazy loading in Next.js helps improve the initial loading performance of an application by decreasing the amount of JavaScript needed to render a route.&lt;/p&gt;

&lt;p&gt;It allows you to defer loading of Client Components and imported libraries, and only include them in the client bundle when they're needed. For example, you might want to defer loading a modal until a user clicks to open it.&lt;/p&gt;

&lt;p&gt;There are two ways you can implement lazy loading in Next.js:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Using Dynamic Imports with next/dynamic&lt;/li&gt;
&lt;li&gt;Using React.lazy() with Suspense&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;By default, Server Components are automatically code split, and you can use streaming to progressively send pieces of UI from the server to the client. Lazy loading applies to Client Components.&lt;/p&gt;

</description>
      <category>webdev</category>
    </item>
    <item>
      <title>Font Optimization</title>
      <dc:creator>Gereltuya Munkhzaya</dc:creator>
      <pubDate>Wed, 27 Sep 2023 05:12:19 +0000</pubDate>
      <link>https://dev.to/gereltuyamz/font-optimization-3k3o</link>
      <guid>https://dev.to/gereltuyamz/font-optimization-3k3o</guid>
      <description>&lt;h3&gt;
  
  
  Google Fonts
&lt;/h3&gt;

&lt;p&gt;Automatically self-host any Google Font. Fonts are included in the deployment and served from the same domain as your deployment. No requests are sent to Google by the browser.&lt;/p&gt;

&lt;p&gt;Get started by importing the font you would like to use from next/font/google as a function. We recommend using variable fonts for the best performance and flexibility.&lt;/p&gt;

&lt;p&gt;To use the font in all your pages, add it to _app.js file under /pages as shown below:&lt;/p&gt;

&lt;p&gt;Apply the font in &lt;/p&gt;
&lt;br&gt;
You can also use the font without a wrapper and className by injecting it inside the  as follows:&lt;br&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Inter } from 'next/font/google'

const inter = Inter({ subsets: ['latin'] })

export default function MyApp({ Component, pageProps }) {
  return (
    &amp;lt;&amp;gt;
      &amp;lt;style jsx global&amp;gt;{`
        html {
          font-family: ${inter.style.fontFamily};
        }
      `}&amp;lt;/style&amp;gt;
      &amp;lt;Component {...pageProps} /&amp;gt;
    &amp;lt;/&amp;gt;
  )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


</description>
      <category>webdev</category>
    </item>
    <item>
      <title>Image Optimization in Next js</title>
      <dc:creator>Gereltuya Munkhzaya</dc:creator>
      <pubDate>Wed, 27 Sep 2023 05:09:10 +0000</pubDate>
      <link>https://dev.to/gereltuyamz/image-optimization-in-next-js-1e0f</link>
      <guid>https://dev.to/gereltuyamz/image-optimization-in-next-js-1e0f</guid>
      <description>&lt;p&gt;According to Web Almanac, images account for a huge portion of the typical website’s page weight and can have a sizable impact on your website's LCP performance.&lt;/p&gt;

&lt;p&gt;The Next.js Image component extends the HTML &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; element with features for automatic image optimization:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Size Optimization:&lt;/strong&gt; Automatically serve correctly sized images for each device, using modern image formats like WebP and AVIF.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Visual Stability:&lt;/strong&gt; Prevent layout shift automatically when images are loading.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Faster Page Loads:&lt;/strong&gt; Images are only loaded when they enter the viewport using native browser lazy loading, with optional blur-up placeholders.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Asset Flexibility:&lt;/strong&gt; On-demand image resizing, even for images stored on remote servers&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Local Images
&lt;/h3&gt;

&lt;p&gt;To use a local image, import your .jpg, .png, or .webp image files.&lt;/p&gt;

&lt;p&gt;Next.js will automatically determine the width and height of your image based on the imported file. These values are used to prevent Cumulative Layout Shift while your image is loading.&lt;/p&gt;

&lt;h3&gt;
  
  
  Remote Images
&lt;/h3&gt;

&lt;p&gt;To use a remote image, the src property should be a URL string.&lt;/p&gt;

&lt;p&gt;Since Next.js does not have access to remote files during the build process, you'll need to provide the width, height and optional blurDataURL props manually.&lt;/p&gt;

&lt;p&gt;The width and height attributes are used to infer the correct aspect ratio of image and avoid layout shift from the image loading in. The width and height do not determine the rendered size of the image file. Learn more about Image Sizing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Domains
&lt;/h3&gt;

&lt;p&gt;Sometimes you may want to optimize a remote image, but still use the built-in Next.js Image Optimization API. To do this, leave the loader at its default setting and enter an absolute URL for the Image src prop.&lt;/p&gt;

&lt;p&gt;To protect your application from malicious users, you must define a list of remote hostnames you intend to use with the next/image component.&lt;/p&gt;

</description>
      <category>nextjs</category>
    </item>
  </channel>
</rss>
