Category Archives: HTML and CSS

Advantages and Disadvantages of React

As of right now, front-end community has fully embraced React. Still, there are a lot of developers who consciously decide against using React and choose Vue, Angular, or even Svelte. This is not to say that React is not useful. It is in fact the best tool for building interactive interfaces right now. I wanted to dedicate this article to breaking down advantages and disadvantages of React.

Advantages

Easy to figure out

There’s a wealth of information available about React and its practical use cases. Official documentation is well written. In addition to that, there are plenty of video tutorials. Most important React concepts are based on JavaScript. So, if you’re someone who understands JavaScript well, then you can figure out React within few months or even weeks.

Reusable components

React saves you from having to write the same code over and over again. Certain parts of a website usually follow the same pattern and organization. For example, blog posts are all designed the same way and they have the same structure. The only different thing between blog posts is their content – title, text, and so on.

React web apps are like component trees. The same parent component can have many child components of the same type. You create a component once and you can reuse it as many times as you want. Certain components are made up of other components. State and props allow you to maintain data and pass it into child components if necessary.

Virtual DOM

React implements a virtual DOM. This is one integral feature that makes React extremely fast. Virtual DOM is a shadow image of the real DOM. Whenever there are changes in the virtual DOM, React synchronizes virtual and real DOMs and updates it efficiently.

Search Engine Friendly

You can use various static site generators to host your React web app. This way, search engines will be able to index contents on your page. Purely client-based applications can not be indexed in search engines.

Supporting libraries

React is a popular front-end framework with a large community of developers. Naturally, these developers have created a variety of useful packages and libraries for implementing certain features necessary for web development. For example, use form libraries for validation or to clear form after submit.

Disadvantages

Fast pace of updates

React is constantly evolving. Any web developer who wants to build web apps in React needs to stay up to date to changes. For example, React v16.8 brought a lot of changes. It introduced hooks in functional components. This change alone turned a lot of React world upside down.

Sometimes documentation updates are slow and do not follow immediately.

Only a library

Many people mistakenly call React a front-end framework. Actually, React is only a library. It deals with presentational part of the application. It does not have built-in solutions for routing or advanced state management. However, there are many supporting libraries like react-router and redux that help.

JSX

For me personally, JSX is an advantage. It allows you to embed JavaScript expression in the structure. This allows you to create dynamic interfaces. However, there’s definitely a learning curve. Many beginners struggle with rules of JSX. SimpleFrontEnd has excellent guides on how to implement common dynamic features using JSX.

Three different selectors in CSS

CSS is an essential tool for web developers. We use it to specify the appearance of HTML elements, their positioning on the page, and even responsive features of the page. So needless to say, as a web developer, you need to master CSS with all of its intricate details to be good at your job.

Basics of CSS are simple, but if you want to do something specific, you might come across difficulties. Changing one thing can lead to difficulties with other elements, and then you need to fix those as well. It can be a nightmare.

In this article, we’ll discuss selectors in CSS.

Selectors are basically how you ‘specify’ which HTML elements the CSS rules should be applied to. You can select elements by their type, for example specify that the CSS rule should apply to div elements. This is good, but it’s too general for complex applications. Most of the time you don’t want your CSS rules to apply to all elements of the same type.

CSS makes it really easy to specify elements for styles. Simply write the name of the element and then you can follow it with specific CSS rules.

Class selectors are a little more specific. Basically, you can define a style and give it a name. And any elements associated with that name will get the appearance specified in the style. Classes are set using the class attribute on HTML elements. In CSS, you define classes by preceding the name of the class with a dot. Also, people tend to write classes in a camelCase format. For example, if you want to define class with a name ‘special container’, CSS code would look like this:

.specialContainer {

                border: 2px solid yellow

}

Finally, you can also specify styles for HTML elements by using the id. Similarly, elements can be assigned id values using the id attribute. Each element has unique id, so this is the most specific of all three types of selectors. id is useful when you want to style outliers, and to ensure that a specific element looks the way you want it to look, or is positioned where you want it to be.

Let’s finish this article by comparing three different selectors and their most appropriate use cases. I don’t like using element selectors, because they are too general. However, they have legitimate use cases, like when you want to style all paragraph elements in your web app, or want to give all containers some padding.

In my experience, class selectors are the most useful, and based on what I’ve seen, other web devs most commonly use classes as well. They give you the ability to define groups of elements and style them as needed. Also, each HTML element can have multiple classes. So you can do something like this: define a specific ‘look’, or specific ‘position’ you want the element to have, and store that in a class name. Then you can set this class to an HTML element, as well as other classes. Instead of having one rigid class that has all the rules, you have more versatile, larger number of classes, and apply them as needed.

Also, classes override general element selectors. You can use this to your advantage. For example, use element selectors for a more general rule, and then have a class for more specific styling. If you want some of the paragraphs to be styled differently from the general rule, simply apply the class.

Another great thing about styling HTML elements with classes is that JavaScript allows you to conditionally add classes. Frameworks like React allow you to add conditional styles to elements as well. Here’s a great article on adding classNames if condition is true in React.

Finally, id selectors are the most specific of all. They should only be used for outlier cases. In ideal scenario, you would not need to use id selectors at all. It should be said that id selectors override normal CSS styles.