<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title>Trung.Do Duc Blog</title>
	<subtitle>Trung. Do Duc’s blog about life, art, design, film, television, music, dogs, and more.</subtitle>
	
	<link href="https://2dtrung.blog/feed/feed.xml" rel="self"/>
	<link href="https://2dtrung.blog/"/>
	<updated>2024-06-09T16:00:00Z</updated>
	<id>https://2dtrung.blog/</id>
	<author>
		<name>Trung. Do Duc</name>
		<email>sductrung@gmail.com</email>
	</author>
			<entry>
				<title>Understanding the GraphQL Type System</title>
				<link href="https://2dtrung.blog/2024/06/09/understanding-the-graphql-type-system/"/>
				<updated>2024-06-09T21:36:00Z</updated>
				<id>https://2dtrung.blog/2024/06/09/understanding-the-graphql-type-system/</id>
				<content type="html">&lt;h1 id=&quot;introduction&quot; tabindex=&quot;-1&quot;&gt;Introduction &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/06/09/understanding-the-graphql-type-system/#introduction&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;GraphQL is a modern solution for facilitating the communication between a front end and a data source. All of the details and capabilities of a GraphQL implementation are laid out in the GraphQL Schema. In order to write a functioning GraphQL schema, you must understand the GraphQL Type System.&lt;/p&gt;
&lt;p&gt;In this article, you will learn about GraphQL types: the five built-in &lt;strong&gt;scalar types&lt;/strong&gt;, &lt;strong&gt;Enums&lt;/strong&gt;, &lt;strong&gt;the List&lt;/strong&gt; and &lt;strong&gt;Non-Null&lt;/strong&gt; wrapping types, &lt;strong&gt;Object types&lt;/strong&gt;, and the &lt;strong&gt;abstract Interface&lt;/strong&gt; and &lt;strong&gt;Union types&lt;/strong&gt; that work alongside them. You will review examples for each type and learn how to use them to build a complete GraphQL schema.&lt;/p&gt;
&lt;h1 id=&quot;prerequisites&quot; tabindex=&quot;-1&quot;&gt;Prerequisites &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/06/09/understanding-the-graphql-type-system/#prerequisites&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;To get the most out of this tutorial, you should have:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;An understanding of the fundamental concepts of GraphQL, which are laid out in An Introduction to GraphQL.&lt;/li&gt;
&lt;li&gt;A GraphQL environment&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;scalar-types&quot; tabindex=&quot;-1&quot;&gt;Scalar Types &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/06/09/understanding-the-graphql-type-system/#scalar-types&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;All the data in a GraphQL schema ultimately resolve to various &lt;a href=&quot;https://spec.graphql.org/June2018/#sec-Scalars&quot;&gt;scalar types&lt;/a&gt;, which represent primitive values. GraphQL responses can be represented as a tree, and the scalar types are the leaves at the ends of the tree. There can be many levels in a nested response, but the last level will always resolve to a scalar (or Enum) type. GraphQL comes with five built-in scalar types: &lt;strong&gt;Int&lt;/strong&gt;, &lt;strong&gt;Float&lt;/strong&gt;, &lt;strong&gt;String&lt;/strong&gt;, &lt;strong&gt;Boolean&lt;/strong&gt;, and &lt;strong&gt;ID&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Int&lt;/strong&gt; &lt;br /&gt;
Int is a signed 32-bit non-fractional numerical value. It is a signed (positive or negative) integer that does not include decimals. The maximum value of a signed 32-bit integer is &lt;strong&gt;2,147,483,647&lt;/strong&gt;. This is one of the two built-in scalars used for numerical data.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Float&lt;/strong&gt; &lt;br /&gt;
A Float is a signed double-precision fractional value. It is a signed (positive or negative) number that contains a decimal point, such as &lt;strong&gt;1.2&lt;/strong&gt;. This is the other built-in scalar used for numerical data.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;String&lt;/strong&gt; &lt;br /&gt;
A String is a &lt;strong&gt;UTF-8&lt;/strong&gt; character sequence. The &lt;strong&gt;String&lt;/strong&gt; type is used for any textual data. This can also include data like very large numbers. Most custom scalars will be types of string data.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Boolean&lt;/strong&gt; &lt;br /&gt;
A Boolean is a &lt;strong&gt;true&lt;/strong&gt; or &lt;strong&gt;false&lt;/strong&gt; value.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;ID&lt;/strong&gt; &lt;br /&gt;
An ID is a unique identifier. This value is always serialized as a string, even if the ID is numerical. An ID type might be commonly represented with a &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Glossary/UUID&quot;&gt;Universally Unique Identifier (UUID)&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Custom Scalars&lt;/strong&gt; &lt;br /&gt;
In addition to these built-in scalars, the scalar keyword can be used to define a custom scalar. You can use custom scalars to create types that have additional server-level validation, such as &lt;strong&gt;Date&lt;/strong&gt;, &lt;strong&gt;Time&lt;/strong&gt;, or &lt;strong&gt;Url&lt;/strong&gt;.
The server will know how to handle interactions with this new type using the &lt;a href=&quot;https://graphql.org/graphql-js/type/&quot;&gt;GraphQLScalarType&lt;/a&gt;.&lt;/p&gt;
&lt;h1 id=&quot;enum-type&quot; tabindex=&quot;-1&quot;&gt;Enum Type &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/06/09/understanding-the-graphql-type-system/#enum-type&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;The &lt;a href=&quot;https://spec.graphql.org/June2018/#sec-Enums&quot;&gt;Enum type&lt;/a&gt;, also known as an Enumerator type, describes a set of possible values.&lt;/p&gt;
&lt;p&gt;Using the Fantasy Game API theme from other tutorials in the series, you might make an enum for the game characters&#39; &lt;strong&gt;Job&lt;/strong&gt; and &lt;strong&gt;Species&lt;/strong&gt; with all the values the system will accept for them. An Enum is defined with the enum keyword, like so:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://2dtrung.blog/img/graphql-type-system-1.png&quot; alt=&quot;enumTypeExample1&quot; /&gt;&lt;/p&gt;
&lt;p&gt;In this way, it is guaranteed that the Job of a character is &lt;strong&gt;FIGHTER&lt;/strong&gt; or &lt;strong&gt;WIZARD&lt;/strong&gt; and can never accidentally be &amp;quot;purple&amp;quot; or some other random string, which could be possible if you used a String type instead of making a custom Enum. Enums are written in all-caps by convention.&lt;/p&gt;
&lt;p&gt;Enums can also be used as the accepted values in arguments. For example, you might make a Hand enum to denote whether a weapon is single-handed (like a short sword) or double-handed (like a heavy axe), and use that to determine whether one or two can be equipped:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://2dtrung.blog/img/graphql-type-system-2.png&quot; alt=&quot;enumTypeExample2&quot; /&gt;&lt;/p&gt;
&lt;p&gt;The Hand enum has been declared with &lt;strong&gt;SINGLE&lt;/strong&gt; and &lt;strong&gt;DOUBLE&lt;/strong&gt; as values, and the argument on the weapons field has a default value of &lt;strong&gt;SINGLE&lt;/strong&gt;, meaning if no argument is passed then it will fall back to SINGLE.&lt;/p&gt;
&lt;h1 id=&quot;conclusion&quot; tabindex=&quot;-1&quot;&gt;Conclusion &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/06/09/understanding-the-graphql-type-system/#conclusion&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;In this tutorial, you learned about many of the types that define the &lt;a href=&quot;https://graphql.org/learn/schema/#type-system&quot;&gt;GraphQL type system&lt;/a&gt;. The most fundamental types are the scalar types, which are the values that act as the leaves on the schema tree, and consist of &lt;strong&gt;Int&lt;/strong&gt;, &lt;strong&gt;Float&lt;/strong&gt;, &lt;strong&gt;String&lt;/strong&gt;, &lt;strong&gt;Boolean&lt;/strong&gt;, &lt;strong&gt;ID&lt;/strong&gt;, and any custom scalar that a GraphQL implementation decides to create. Enums are lists of valid constant values that can be used when you need more control over a response than simply declaring it as a String, and are also leaves on the schema tree. List and Non-Null types are known as type modifiers, or wrapping types, and they can define other types as collections or required, respectively. Objects are the branches of the schema tree, and almost everything in a GraphQL schema is a type of Object, including the &lt;strong&gt;query&lt;/strong&gt;, &lt;strong&gt;mutation&lt;/strong&gt;, and &lt;strong&gt;subscription&lt;/strong&gt; entrypoints. Interface and Union types are abstract types that can be helpful in defining Objects.&lt;/p&gt;
&lt;p&gt;For further learning, you can practice creating and modifying a GraphQL schema by reading the &lt;a href=&quot;https://www.digitalocean.com/community/tutorials/how-to-set-up-a-graphql-api-server-in-node-js&quot;&gt;How to Set Up a GraphQL API Server in Node.js&lt;/a&gt; tutorial to have a working GraphQL server environment.&lt;/p&gt;
&lt;p&gt;I hope you enjoyed the article.&lt;/p&gt;
&lt;p&gt;See you in the next post.&lt;/p&gt;
&lt;p&gt;Have a great day!&lt;/p&gt;
</content>
			</entry>
			<entry>
				<title>Keep It Simple, Stupid</title>
				<link href="https://2dtrung.blog/2024/06/04/keep-it-simple-stupid/"/>
				<updated>2024-06-04T02:07:00Z</updated>
				<id>https://2dtrung.blog/2024/06/04/keep-it-simple-stupid/</id>
				<content type="html">&lt;p&gt;Today, we&#39;re going to talk about &lt;strong&gt;the KISS principle in JavaScript&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;It&#39;s all about &lt;strong&gt;simplifying your JavaScript code&lt;/strong&gt;. You:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;reduce bugs&lt;/li&gt;
&lt;li&gt;enhance readability&lt;/li&gt;
&lt;li&gt;improve maintainability&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You will &lt;strong&gt;save time and effort&lt;/strong&gt; in the long run.
Many devs struggle with overly complex code, leading to confusion and errors. Embracing simplicity prevents these pitfalls and streamlines your development process.&lt;/p&gt;
&lt;h1 id=&quot;keep-it-simple%2C-stupid-%3D-simplicity-%3D-smoother-development-%26-easier-maintenance&quot; tabindex=&quot;-1&quot;&gt;Keep It Simple, Stupid = Simplicity = Smoother Development &amp;amp; Easier Maintenance &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/06/04/keep-it-simple-stupid/#keep-it-simple%2C-stupid-%3D-simplicity-%3D-smoother-development-%26-easier-maintenance&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Keep the code &lt;strong&gt;easy to read and understand&lt;/strong&gt;.
If you keep the code simple, you&#39;ll make it easier for all people to fix things when they go wrong.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Don’t make your code too smart.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Make it simple. You and your teammates will thank you in the future when maintaining the code or adding new features.&lt;/p&gt;
&lt;p&gt;Here are some simple code examples to see &lt;strong&gt;how to apply this principle&lt;/strong&gt;:&lt;/p&gt;
&lt;h1 id=&quot;arrow-functions&quot; tabindex=&quot;-1&quot;&gt;Arrow Functions &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/06/04/keep-it-simple-stupid/#arrow-functions&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;https://2dtrung.blog/img/preview.png&quot; alt=&quot;parentFunction&quot; /&gt;&lt;/p&gt;
&lt;h1 id=&quot;short-circuit-evaluation&quot; tabindex=&quot;-1&quot;&gt;Short-Circuit Evaluation &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/06/04/keep-it-simple-stupid/#short-circuit-evaluation&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;https://2dtrung.blog/img/e6362bdf-c2de-4297-b018-8ae6410266bf_1126x1080.png&quot; alt=&quot;parentFunction&quot; /&gt;&lt;/p&gt;
&lt;h1 id=&quot;implicit-return&quot; tabindex=&quot;-1&quot;&gt;Implicit Return &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/06/04/keep-it-simple-stupid/#implicit-return&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;https://2dtrung.blog/img/aaf98934-7541-4e15-a446-268d1a36a202_1144x706.png&quot; alt=&quot;parentFunction&quot; /&gt;&lt;/p&gt;
&lt;h1 id=&quot;default-parameters&quot; tabindex=&quot;-1&quot;&gt;Default Parameters &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/06/04/keep-it-simple-stupid/#default-parameters&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;https://2dtrung.blog/img/8983d479-ec65-4c44-b719-918f3f9e7382_1194x818.png&quot; alt=&quot;parentFunction&quot; /&gt;&lt;/p&gt;
&lt;h1 id=&quot;simple-functions&quot; tabindex=&quot;-1&quot;&gt;Simple functions &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/06/04/keep-it-simple-stupid/#simple-functions&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;https://2dtrung.blog/img/0fb938e4-d328-4327-a50b-65b189d03751_1380x710.png&quot; alt=&quot;parentFunction&quot; /&gt;&lt;/p&gt;
&lt;h1 id=&quot;destructuring&quot; tabindex=&quot;-1&quot;&gt;Destructuring &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/06/04/keep-it-simple-stupid/#destructuring&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;https://2dtrung.blog/img/70f5c4ce-8951-4fde-822a-a00b366a9700_874x930.png&quot; alt=&quot;parentFunction&quot; /&gt;&lt;/p&gt;
&lt;h1 id=&quot;spread-operator&quot; tabindex=&quot;-1&quot;&gt;Spread Operator &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/06/04/keep-it-simple-stupid/#spread-operator&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;https://2dtrung.blog/img/07e9cc98-3d32-40af-833b-9b715cbcc8bd_1262x1194.png&quot; alt=&quot;parentFunction&quot; /&gt;&lt;/p&gt;
&lt;h1 id=&quot;conclusion&quot; tabindex=&quot;-1&quot;&gt;Conclusion &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/06/04/keep-it-simple-stupid/#conclusion&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Embracing the KISS principle in your JavaScript coding practices can significantly &lt;strong&gt;improve your productivity and code quality&lt;/strong&gt;. By keeping it simple, you&#39;ll write better code and make your development process more enjoyable and efficient.&lt;/p&gt;
&lt;p&gt;So, next time you&#39;re tempted to overcomplicate things… Remember: &lt;strong&gt;Keep It Simple!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I hope you enjoyed the article.&lt;/p&gt;
&lt;p&gt;See you in the next post.&lt;/p&gt;
&lt;p&gt;Have a great day!&lt;/p&gt;
</content>
			</entry>
			<entry>
				<title>Testing in Front-End Development</title>
				<link href="https://2dtrung.blog/2024/06/01/testing-in-front-end-development/"/>
				<updated>2024-06-01T20:57:00Z</updated>
				<id>https://2dtrung.blog/2024/06/01/testing-in-front-end-development/</id>
				<content type="html">&lt;p&gt;Today, we&#39;ll delve into the importance of testing in front-end development and showcase 3 types of testing we can use in projects.&lt;/p&gt;
&lt;p&gt;Testing in front-end development ensures code reliability, catches bugs early, and boosts confidence in deployments, ultimately enhancing the user experience and developer productivity.&lt;/p&gt;
&lt;p&gt;Many developers overlook testing in front-end development, leading to increased debugging time, higher chances of bugs in production, and a compromised user experience.&lt;/p&gt;
&lt;h1 id=&quot;front-end-testing-isn&#39;t-just-an-extra-step.-it&#39;s-fundamental-to-delivering-high-quality-web-applications-that-meet-user-expectations-and-maintain-code-integrity.&quot; tabindex=&quot;-1&quot;&gt;Front-end testing isn&#39;t just an extra step. It&#39;s fundamental to delivering high-quality web applications that meet user expectations and maintain code integrity. &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/06/01/testing-in-front-end-development/#front-end-testing-isn&#39;t-just-an-extra-step.-it&#39;s-fundamental-to-delivering-high-quality-web-applications-that-meet-user-expectations-and-maintain-code-integrity.&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Increased code reliability and stability&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Early detection and prevention of bugs&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Improved developer confidence and productivity&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Examining our application to ensure it functions correctly is crucial. We must ensure no errors slip through when we release our product.&lt;/p&gt;
&lt;p&gt;Conducting manual tests demands significant time and energy to uncover issues. Hence, automating our tests is imperative.&lt;/p&gt;
&lt;p&gt;Diverse test categories exist:&lt;/p&gt;
&lt;p&gt;• Unit tests&lt;/p&gt;
&lt;p&gt;• Integration tests&lt;/p&gt;
&lt;p&gt;• End-to-end tests&lt;/p&gt;
&lt;h1 id=&quot;unit-testing&quot; tabindex=&quot;-1&quot;&gt;Unit testing &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/06/01/testing-in-front-end-development/#unit-testing&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;These tests focus solely on independently examining the smallest components of our application.&lt;/p&gt;
&lt;p&gt;I recommend using Jest, which is recognized as the predominant framework for evaluating JavaScript applications.&lt;/p&gt;
&lt;h1 id=&quot;integration-testing&quot; tabindex=&quot;-1&quot;&gt;Integration testing &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/06/01/testing-in-front-end-development/#integration-testing&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Integration testing involves examining how various application components function together. These tests are more significant than unit tests. Most application evaluations lean towards integration tests.&lt;/p&gt;
&lt;p&gt;The value of integration tests lies in their ability to instill confidence in our application. By scrutinizing the functionality of diverse parts, assessing their relationships, and gauging communication pathways, these tests offer a comprehensive understanding of the system&#39;s performance.&lt;/p&gt;
&lt;p&gt;I recommend using Jest and the React Testing Library to execute integration testing. This methodology ensures that we evaluate application features in a manner that mirrors user interaction, facilitating a thorough examination of functionality.&lt;/p&gt;
&lt;h1 id=&quot;end-to-end-testing&quot; tabindex=&quot;-1&quot;&gt;End-to-end testing &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/06/01/testing-in-front-end-development/#end-to-end-testing&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;These tests allow us to scrutinize vital segments of our application from start to finish, ensuring seamless functionality throughout. Typically, such tests prioritize examining critical features comprehensively.&lt;/p&gt;
&lt;p&gt;End-to-end testing entails evaluating the application as a cohesive whole, encompassing both front-end and back-end components. Typically, these tests involve automating the entire application and ensuring seamless functionality across the system.&lt;/p&gt;
&lt;p&gt;In end-to-end testing, our primary focus is on the &amp;quot;happy path,&amp;quot; verifying that the application performs as anticipated under ideal conditions.&lt;/p&gt;
&lt;p&gt;I recommend using Cypress, a widely used testing framework that executes tests within a headless browser environment. This indicates that the tests will run within an authentic browser environment.&lt;/p&gt;
&lt;h1 id=&quot;conclusion&quot; tabindex=&quot;-1&quot;&gt;Conclusion &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/06/01/testing-in-front-end-development/#conclusion&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Embracing testing in front-end development is crucial for delivering high-quality web applications that meet user expectations and maintain code integrity. By integrating testing into your development workflow, you can ensure code reliability, catch bugs early, and boost developer productivity.&lt;/p&gt;
&lt;p&gt;I hope you enjoyed the article.&lt;/p&gt;
&lt;p&gt;See you in the next post.&lt;/p&gt;
&lt;p&gt;Have a great day!&lt;/p&gt;
</content>
			</entry>
			<entry>
				<title>useMemo in React</title>
				<link href="https://2dtrung.blog/2024/04/26/usememo-in-react/"/>
				<updated>2024-04-26T11:50:00Z</updated>
				<id>https://2dtrung.blog/2024/04/26/usememo-in-react/</id>
				<content type="html">&lt;p&gt;I&#39;m excited to dive deep into the concept of &lt;strong&gt;useMemo&lt;/strong&gt;, a powerful React hook that can help improve the performance of your application. useMemo is a tool that allows you to memoize, or cache, the results of expensive calculations, reducing the need for unnecessary re-computations and enhancing your app&#39;s responsiveness.&lt;/p&gt;
&lt;p&gt;Understanding the mechanics and applications of &lt;strong&gt;useMemo&lt;/strong&gt; is crucial for React developers seeking to optimize their applications. Avoiding unnecessary recalculations can make your app more responsive and resource-efficient, significantly enhancing the user experience.&lt;/p&gt;
&lt;p&gt;Many React developers struggle with the use of &lt;strong&gt;useMemo&lt;/strong&gt;, either overusing or misapplying it when it&#39;s not necessary. This can lead to increased complexity without the desired performance benefits.&lt;/p&gt;
&lt;h1 id=&quot;understand-the-fundamental&quot; tabindex=&quot;-1&quot;&gt;Understand the fundamental &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/04/26/usememo-in-react/#understand-the-fundamental&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;useMemo&lt;/strong&gt; enables you to cache the result of computations between re-renders. This is particularly useful when dealing with expensive computations whose output is determined by specific dependencies. When the dependencies don&#39;t change between re-renders, the result will be cached, saving processing time and resources.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;useMemo&lt;/strong&gt; is very important for optimizing React components render.&lt;/li&gt;
&lt;li&gt;It work by memorizing the output of function with dependencies.&lt;/li&gt;
&lt;li&gt;Overuse and misapplying this can lead complexity without best page performance.&lt;/li&gt;
&lt;li&gt;Ideal for expensive calculation that do not change too often.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;when-to-use&quot; tabindex=&quot;-1&quot;&gt;When to use &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/04/26/usememo-in-react/#when-to-use&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;For heavy calculations in render methods.&lt;/li&gt;
&lt;li&gt;When the props of children require expensive calculations.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;understand-the-dependency&quot; tabindex=&quot;-1&quot;&gt;Understand the dependency &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/04/26/usememo-in-react/#understand-the-dependency&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Dependencies are crucial in &lt;strong&gt;useMemo&lt;/strong&gt;. They determine when the cached output of a calculation should be used or when a new calculation should be performed. Mismanaging dependencies can lead to frequent, unnecessary recalculations.&lt;/p&gt;
&lt;h1 id=&quot;common-misunderstanding&quot; tabindex=&quot;-1&quot;&gt;Common misunderstanding &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/04/26/usememo-in-react/#common-misunderstanding&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;useMemo&lt;/strong&gt; isn&#39;t a common silver bullet for all performance issues&lt;/li&gt;
&lt;li&gt;It should not used to fix issues that have poor structure design&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;example&quot; tabindex=&quot;-1&quot;&gt;Example &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/04/26/usememo-in-react/#example&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Considering &lt;strong&gt;TodoList&lt;/strong&gt; component where filtering todos is an expensive operation. Using &lt;strong&gt;useMemo&lt;/strong&gt; can cache the result of filtering todoList:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://2dtrung.blog/img/useMemo-filtering-todoList.png&quot; alt=&quot;useMemo example&quot; /&gt;&lt;/p&gt;
&lt;h1 id=&quot;conclusion&quot; tabindex=&quot;-1&quot;&gt;Conclusion &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/04/26/usememo-in-react/#conclusion&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;useMemo&lt;/strong&gt; is a powerful tool in React development for optimizing application performance. When used correctly, it can effectively reduce unnecessary computations, leading to a smoother and faster app. Remember, the real power of useMemo lies in understanding when and where to use it. You must thoughtfully apply it in your React applications.&lt;/p&gt;
&lt;p&gt;If you&#39;re still not fully clear on &lt;strong&gt;useMemo&lt;/strong&gt;, I highly recommend reading the official React documentation:: &lt;a href=&quot;https://react.dev/reference/react/useMemo&quot;&gt;https://react.dev/reference/react/useMemo&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I hope you enjoyed the article.
If you have any questions, feel free to reply to my email or leave a comment in the post. You can also contact me in Linkedin.&lt;/p&gt;
&lt;p&gt;See you in the next post.&lt;/p&gt;
</content>
			</entry>
			<entry>
				<title>Mastering Front-End Development</title>
				<link href="https://2dtrung.blog/2024/02/21/mastering-front-end-development/"/>
				<updated>2024-02-21T21:13:00Z</updated>
				<id>https://2dtrung.blog/2024/02/21/mastering-front-end-development/</id>
				<content type="html">&lt;p&gt;Mastering Front-End Development: Navigating the Complexities and Seizing Opportunities&lt;/p&gt;
&lt;p&gt;Learning new things in the ever-evolving world of front-end development can be challenging. With a vast array of tools, skills, techniques, and the rise of AI, it&#39;s easy to feel overwhelmed. However, by embracing the complexities and focusing on the opportunities, we can shape the digital landscape with creativity and innovation.&lt;/p&gt;
&lt;p&gt;Mastering front-end development is essential for creating engaging and functional web applications that provide a seamless user experience across various devices and browsers. Many people struggle with front-end development due to the attention to detail and specialized knowledge required in coding and design. Common pain points include lack of consistency, performance issues, and difficulties in feature development&lt;/p&gt;
&lt;h1 id=&quot;instead-of-thinking-about-many-difficult-in-front-end-development%2C-why-we-don&#39;t-take-a-look-on-opportunity-for-creative-and-innovative-in-shaping-the-digital-landscape&quot; tabindex=&quot;-1&quot;&gt;Instead of thinking about many difficult in front-end development, why we don&#39;t take a look on opportunity for creative and innovative in shaping the digital landscape &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/02/21/mastering-front-end-development/#instead-of-thinking-about-many-difficult-in-front-end-development%2C-why-we-don&#39;t-take-a-look-on-opportunity-for-creative-and-innovative-in-shaping-the-digital-landscape&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Front-end development requires technical expertise, creativity, and attention to detail. Building responsive designs, ensuring cross-browser compatibility, and optimizing performance demand rigorous discipline and continuous learning.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You must understand how challenge front-end development are, including responsive design and cross-browser compatibility.&lt;/li&gt;
&lt;li&gt;Develop strong discipline and consistency in coding practices.&lt;/li&gt;
&lt;li&gt;Priority on performance for enhance user experiences.&lt;/li&gt;
&lt;li&gt;Always engage to learn new things, your knowledge will be outdate soon.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;some-challenges-you-need-to-know-soon-and-overcome-it&quot; tabindex=&quot;-1&quot;&gt;Some challenges you need to know soon and overcome it &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/02/21/mastering-front-end-development/#some-challenges-you-need-to-know-soon-and-overcome-it&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Instead of dwelling on the difficulties, let&#39;s explore the opportunities that front-end development presents. By understanding the challenges and developing strategies to overcome them, we can unleash our creativity and make a meaningful impact on the digital world.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Key Challenges and Strategies:&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;1.Responsive Design&lt;/strong&gt;:  Utilize CSS media queries and flexible layouts to create designs that adapt to various screen sizes. This ensures a consistent and optimized user experience across devices.&lt;br /&gt;
&lt;strong&gt;2.Cross-Browser Compatibility&lt;/strong&gt;: Test your code across browsers and devices to ensure consistent rendering and functionality. This step is crucial for delivering a seamless experience to your users.&lt;br /&gt;
&lt;strong&gt;3.Performance Optimization&lt;/strong&gt;: Minimize file sizes, reduce HTTP requests, and utilize techniques like lazy loading to improve page load times. Optimizing performance enhances user satisfaction and engagement.&lt;br /&gt;
&lt;strong&gt;4.Feature Implementation&lt;/strong&gt;: Break down complex features into smaller tasks and leverage frameworks like React or Vue.js for efficient development. This approach helps manage the complexity of front-end development and streamlines the implementation process.&lt;br /&gt;&lt;/p&gt;
&lt;h1 id=&quot;conclusion&quot; tabindex=&quot;-1&quot;&gt;Conclusion &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/02/21/mastering-front-end-development/#conclusion&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Front-end development is undoubtedly challenging, but it also presents immense opportunities for growth and innovation. By cultivating strong discipline, consistency, and a belief in yourself, you can overcome the obstacles and master the art of front-end development.&lt;/p&gt;
&lt;p&gt;Trust the process, make a plan, and follow through. With dedication and a willingness to learn, you can transform the digital landscape and create experiences that captivate your users.&lt;/p&gt;
&lt;p&gt;Remember, front-end development is hard, but it&#39;s a journey worth embarking on. Embrace the challenges, seize the opportunities, and unleash your creativity to shape the future of the web.&lt;/p&gt;
&lt;p&gt;I hope you enjoyed the article.&lt;/p&gt;
&lt;p&gt;If you have any questions, feel free to reply to the email or leave a comment in the post. You can also contact me on LinkedIn.&lt;/p&gt;
&lt;p&gt;See you in the next post.&lt;/p&gt;
</content>
			</entry>
			<entry>
				<title>Đừng bỏ lỡ concept Javascript quan trọng này - Closures</title>
				<link href="https://2dtrung.blog/2024/02/14/djung-bo-lo-concept-javascript-quan-trong-nay-closures/"/>
				<updated>2024-02-14T02:00:00Z</updated>
				<id>https://2dtrung.blog/2024/02/14/djung-bo-lo-concept-javascript-quan-trong-nay-closures/</id>
				<content type="html">&lt;p&gt;Hôm nay, chúng ta sẽ tìm hiểu bằng cách nào mà closures hoạt động trong Javascript bằng 1 ví dụ đơn giản.&lt;/p&gt;
&lt;p&gt;Hiểu được closures là rất quan trọng để thành thạo được Javascript vì nó kích hoạt patterns hết sức mạnh mẽ như data privacy và function factories. Hơn thế nữa, đây là 1 chủ đề hết sức phổ biến trong phỏng vấn.&lt;/p&gt;
&lt;p&gt;Rất nhiều dev Javascript gặp khó khăn với closures do tính trừu tượng của nó. Chúng ta sẽ giải thích 1 cách đơn giản và dễ hiểu có thể nắm bắt được khái niệm này 1 cách dễ dàng.&lt;/p&gt;
&lt;h1 id=&quot;hi%E1%BB%83u-%C4%91%C6%B0%E1%BB%A3c-closures-%C4%91%E1%BB%83-ph%C3%A1t-huy-to%C3%A0n-b%E1%BB%99-nh%E1%BB%AFng-k%E1%BB%B9-n%C4%83ng-v%E1%BB%81-javascript-ti%E1%BB%81m-t%C3%A0ng-c%E1%BB%A7a-b%E1%BA%A1n&quot; tabindex=&quot;-1&quot;&gt;Hiểu được Closures để phát huy toàn bộ những kỹ năng về Javascript tiềm tàng của bạn &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/02/14/djung-bo-lo-concept-javascript-quan-trong-nay-closures/#hi%E1%BB%83u-%C4%91%C6%B0%E1%BB%A3c-closures-%C4%91%E1%BB%83-ph%C3%A1t-huy-to%C3%A0n-b%E1%BB%99-nh%E1%BB%AFng-k%E1%BB%B9-n%C4%83ng-v%E1%BB%81-javascript-ti%E1%BB%81m-t%C3%A0ng-c%E1%BB%A7a-b%E1%BA%A1n&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Closures là 1 khái niệm cơ bản trong Javascript, cho phép các function giữ quyền truy cập tới các variable từ scope của chúng ngay cả khi scope đó đã đóng.&lt;/p&gt;
&lt;p&gt;Bây giờ chúng ta sẽ tạo 1 hàm có tên là &lt;strong&gt;parentFunction&lt;/strong&gt;:
&lt;img src=&quot;https://2dtrung.blog/img/create-parent-function.png&quot; alt=&quot;parentFunction&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Bên trong hàm, ta thấy biến &lt;strong&gt;let&lt;/strong&gt; có tên &lt;strong&gt;num&lt;/strong&gt; với &lt;strong&gt;console.log&lt;/strong&gt;
Sau đó, ta tạo 1 hàm có tên là &lt;strong&gt;childFunction&lt;/strong&gt; và trả về hàm đó. Hàm &lt;strong&gt;childFunction&lt;/strong&gt; có giá trị log ra là &lt;strong&gt;num++&lt;/strong&gt;. Hàm &lt;strong&gt;childFunction&lt;/strong&gt; có quyền truy cập giá trị &lt;strong&gt;num&lt;/strong&gt; vì nó có quyền truy cập vào scope hàm cha của nó trong đó có giá trị &lt;strong&gt;num&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Cuối cùng, chúng ta sẽ tạo 1 hàm có tên là &lt;strong&gt;finalFunction&lt;/strong&gt; bằng cách thực thi &lt;strong&gt;parentFunction&lt;/strong&gt;:
&lt;img src=&quot;https://2dtrung.blog/img/create-final-function.png&quot; alt=&quot;finalFunction&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Nếu chúng ta chạy đoạn code này, thì đây chính xác là những gì hàm &lt;strong&gt;finalFunction&lt;/strong&gt; sẽ được log ra:
&lt;img src=&quot;https://2dtrung.blog/img/how-final-function.png&quot; alt=&quot;How finalFunction&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Điều quan trọng là bên ngoài hàm &lt;strong&gt;parentFunction&lt;/strong&gt;, chúng ta không thể truy cập giá trị num. Chúng ta sẽ nhận về error nếu log như cách làm dưới đây:
&lt;img src=&quot;https://2dtrung.blog/img/error-log-final-function.png&quot; alt=&quot;Error log by finalFunction&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Tuy nhiên, nếu chúng ta thực thi hàm &lt;strong&gt;finalFunction&lt;/strong&gt;:
&lt;img src=&quot;https://2dtrung.blog/img/execute-final-function.png&quot; alt=&quot;Execute finalFunction&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Chúng ta sẽ thấy giá trị &lt;strong&gt;num&lt;/strong&gt; tăng lên 1.
&lt;img src=&quot;https://2dtrung.blog/img/num-increase-by-1.png&quot; alt=&quot;num increase by 1&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Chúng ta thấy giá trị được log ra bằng 1 vì &lt;strong&gt;console.log(num)&lt;/strong&gt; đầu tiên được thực thi khi hàm &lt;strong&gt;finalFunction&lt;/strong&gt; được tạo thông qua &lt;strong&gt;parentFunction&lt;/strong&gt;. Và sau đó, giá trị 2 được hiện thị bởi vì chúng ta chạy hàm &lt;strong&gt;finalFunction&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Hàm &lt;strong&gt;finalFunction&lt;/strong&gt; có quyền truy cập vào giá trị &lt;strong&gt;num&lt;/strong&gt; mặc dù hàm &lt;strong&gt;parentFunction&lt;/strong&gt; đã được gọi và closed lại.&lt;/p&gt;
&lt;p&gt;Một closure được tạo ra khi chúng ta định nghĩa 1 hàm chứ không phải khi 1 hàm đó thực thi.&lt;/p&gt;
&lt;p&gt;Có thể hiểu ngắn ngọn, xúc tích như khái niệm trên w3schools:
&lt;strong&gt;Closures là 1 hàm có quyền truy cập vào scope của cha nó, thậm chí là sau khi hàm cha đã bị closed&lt;/strong&gt;&lt;/p&gt;
&lt;h1 id=&quot;t%E1%BB%95ng-k%E1%BA%BFt-l%E1%BA%A1i&quot; tabindex=&quot;-1&quot;&gt;Tổng kết lại &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/02/14/djung-bo-lo-concept-javascript-quan-trong-nay-closures/#t%E1%BB%95ng-k%E1%BA%BFt-l%E1%BA%A1i&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Hiểu rõ closures là 1 điều hết sức quan trọng để đi sâu vào các khái niệm nâng cao hơn trong front-end development. Ngoài ra, đây là 1 chủ để phổ biến trong phỏng vấn. Vì vậy bằng cách nắm bắt khái niệm này, bạn sẽ nâng cao kỹ năng đối với 1 front-end developer.&lt;/p&gt;
</content>
			</entry>
			<entry>
				<title>Tạm biệt SASS 👋, chào mừng trở lại CSS thuần</title>
				<link href="https://2dtrung.blog/2024/01/02/tam-biet-sass-chao-mung-tro-lai-css-thuan/"/>
				<updated>2024-01-02T13:00:00Z</updated>
				<id>https://2dtrung.blog/2024/01/02/tam-biet-sass-chao-mung-tro-lai-css-thuan/</id>
				<content type="html">&lt;p&gt;Sass đã được trình làng như một công cụ tự biên dịch hoàn toàn dưới local, hình thành nên trục xương sống của những dự án trong xuyên xuất hơn 1 thập kỉ qua. Nó cho phép tổ chức 1 cách hiệu quả, có thể mở rộng và đầy ổn định 1 gói các CSS. Thậm chí đến ngày hôm nay, tôi vẫn cân nhắc rằng Sass thật sự là 1 công cụ đầy mạnh mẽ. Tuy nhiên, khi mà chúng ta đang bước vào năm 2024, không thể phủ nhận rằng CSS đã và đang trải qua sự phát triển cực kì nhanh chóng. Những tính năng mà trước đây là độc tôn của Sass giờ đây hoàn toàn được tích hợp vào trong CSS, bao gồm biến và điểm nhấn gần nhất là: &lt;strong&gt;CSS Nesting&lt;/strong&gt;.&lt;/p&gt;
&lt;h1 id=&quot;variables&quot; tabindex=&quot;-1&quot;&gt;Variables &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/01/02/tam-biet-sass-chao-mung-tro-lai-css-thuan/#variables&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Định nghĩa variables đã là 1 điểm mạnh cực lớn riêng biệt của SCSS, cho phép tập trung kiểm soát rất nhiều thuộc tính, 1 tính năng mà đã không có trong CSS trong 1 thời gian dài. Tuy nhiên, hiện nay, variable có thể được định nghĩa trong CSS bằng 1 cách tương tự như ở trong Sass. Một sự khác biệt đáng kể, tuy nhiên, có phải rằng SCSS variables tồn tại độc lập trong bối cảnh tiền xử lý, trong khi CSS variables có thể sử dụng trong trình duyệt và thập chí được viết đè lên 1 cách dynamically bằng Javascript.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://2dtrung.blog/img/css-variables.png&quot; alt=&quot;CSS variables&quot; /&gt;&lt;/p&gt;
&lt;h1 id=&quot;css-nesting&quot; tabindex=&quot;-1&quot;&gt;CSS Nesting &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/01/02/tam-biet-sass-chao-mung-tro-lai-css-thuan/#css-nesting&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Khả năng xác định các quy tắc style của một thành phần trong một thành phần khác giúp đơn giản hóa đáng kể việc viết CSS. Thay vì sử dụng nhiều lần cùng một bột selector cho các phần tử phụ hoặc pseudo-selectors, nesting cho phép nhóm các phần tử này trong selector cha. Kỹ thuật này dẫn đến một cấu trúc mã rõ ràng, phân cấp và do đó hiệu quả hơn.&lt;/p&gt;
&lt;p&gt;Với &lt;a href=&quot;https://caniuse.com/?search=css%20nesting&quot;&gt;sự hỗ trợ của trình duyệt&lt;/a&gt; hơn 84% đối với CSS Nesting và 86% đối với Nesting Selector, kỹ thuật này ngày càng trở nên dễ tiếp cận.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://2dtrung.blog/img/css-nesting.png&quot; alt=&quot;CSS nesting&quot; /&gt;&lt;/p&gt;
&lt;h1 id=&quot;%3Ais()-pseudo-class&quot; tabindex=&quot;-1&quot;&gt;:is() Pseudo-Class &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/01/02/tam-biet-sass-chao-mung-tro-lai-css-thuan/#%3Ais()-pseudo-class&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;:is()&lt;/strong&gt; pseudo-class cách mạng hóa khái niệm selector bằng cách chấp nhận danh sách các selector và tạo kiểu cho tất cả các phần tử khớp với bất kỳ selector nào trong số này. Điều này hỗ trợ rất nhiều cho việc lựa chọn và styling cho các phần tử trong DOM.&lt;/p&gt;
&lt;p&gt;Thay vì danh sách selector dài, bạn có thể sử dụng &lt;strong&gt;:is()&lt;/strong&gt; để cải thiện khả năng đọc đồng thời tránh bộ chọn dài.&lt;/p&gt;
&lt;h1 id=&quot;%3Ahas()-pseudo-class&quot; tabindex=&quot;-1&quot;&gt;:has() Pseudo-Class &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/01/02/tam-biet-sass-chao-mung-tro-lai-css-thuan/#%3Ahas()-pseudo-class&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;:has()&lt;/strong&gt; pseudo class cung cấp một cách mạnh mẽ để chọn một phần tử dựa trên các phần tử con của nó, tương tự như việc áp dụng các kiểu có điều kiện.&lt;/p&gt;
&lt;h1 id=&quot;truy-v%E1%BA%A5n-v%C3%B9ng-ch%E1%BB%A9a&quot; tabindex=&quot;-1&quot;&gt;Truy vấn vùng chứa &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/01/02/tam-biet-sass-chao-mung-tro-lai-css-thuan/#truy-v%E1%BA%A5n-v%C3%B9ng-ch%E1%BB%A9a&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Truy vấn vùng chứa được coi là sự đổi mới quan trọng nhất trong thiết kế web kể từ CSS3. Họ mở rộng khái niệm Responsive Design bằng cách cho phép các thành phần điều chỉnh dựa trên kích thước vùng chứa của chúng. Technique này cho phép thiết kế của một phần tử thay đổi linh hoạt tùy theo context, dẫn đến thiết kế linh hoạt và thích ứng hơn.&lt;/p&gt;
&lt;p&gt;Nếu tùy chọn vùng chứa có variable &lt;strong&gt;--theme: dark&lt;/strong&gt;, hãy thêm CSS sau.&lt;/p&gt;
&lt;h1 id=&quot;x%E1%BA%BFp-t%E1%BA%A7ng-layers&quot; tabindex=&quot;-1&quot;&gt;Xếp tầng layers &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/01/02/tam-biet-sass-chao-mung-tro-lai-css-thuan/#x%E1%BA%BFp-t%E1%BA%A7ng-layers&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Với xếp tầng layers, chúng ta có thể tránh việc nesting các classes, ID, v.v. để có độ đặc hiệu cao hơn bằng cách chỉ định layer của riêng mình. Bằng cách sử dụng &lt;strong&gt;@layer&lt;/strong&gt; và &lt;strong&gt;@imports&lt;/strong&gt;, chúng ta có thể xây dựng các layer xếp tầng của riêng mình - từ các kiểu có mức độ ưu tiên thấp như đặt lại và mặc định, thông qua các theme, framework và design systems, cho đến các kiểu có mức độ ưu tiên cao nhất như components, utilities và overrides. Các layer xếp chồng cung cấp nhiều quyền kiểm soát hơn.&lt;/p&gt;
&lt;h1 id=&quot;t%C6%B0%C6%A1ng-lai-c%E1%BB%A7a-sass&quot; tabindex=&quot;-1&quot;&gt;Tương lai của SASS &lt;a class=&quot;direct-link&quot; href=&quot;https://2dtrung.blog/2024/01/02/tam-biet-sass-chao-mung-tro-lai-css-thuan/#t%C6%B0%C6%A1ng-lai-c%E1%BB%A7a-sass&quot; aria-hidden=&quot;true&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Có nghĩa là Sass đang trở nên lỗi thời? Không. Mixins và các function, chẳng hạn như chuyển đổi pixel thành rem, vẫn là những lợi thế không thể thay thế của Sass. Tuy nhiên, tôi đã quyết định từ bỏ Sass trong hầu hết các dự án của mình. Thay vào đó, tôi sử dụng block codes và packages được xác định trước trong Sublime Editor, điều này đã cải thiện đáng kể quy trình làm việc của tôi.&lt;/p&gt;
</content>
			</entry>
</feed>
