CodeNewbie Community 🌱

Sebastian9995
Sebastian9995

Posted on

Different ways to design apps in React

Every front-end developer knows about the normal ways to design a web application. Connect external stylesheet with an HTML file, apply classes and that’s it. However, many front-end developers don’t know that there are many other ways to customize the appearance of a web application built in React.

Design web application via external stylesheet

This is the standard approach for styling web applications in CSS. Linking React components with CSS files is pretty similar to how we do it in HTML. First we create a CSS stylesheet, write required CSS rules, and use the import statement to make it available in the React component.

Linking CSS files with React components is good if you’re already familiar with the process of writing CSS rules for styling web applications. Most web developers have been using this syntax for years.

Using inline styles

Many React developers will advise against using inline styles, but there are certain use cases where they are useful. For example, if you are building a prototype of a web application, or just a small application.

In React, inline styles are written as JavaScript objects. And you probably know that React elements are written in JSX. You can set the style attribute of React elements to a JavaScript objects where keys represent CSS properties, and values represent CSS values. For example, something like this:

{backgroundColor: “red”}

As you can see, instead of writing CSS property as you would in a separate stylesheet (‘background-color’), we write it as backgroundColor – two words pushed together and camelCased. Also, the value of this property needs to be a string or other valid JavaScript value. You can also use string interpolation to dynamically style element in React. Here's a guide that explains how that works:

https://simplefrontend.com/string-interpolation-in-react-tutorial-with-examples/

One final detail is that in order to evaluate JavaScript objects as such inside JSX, you need to wrap JavaScript code with an additional pair of curly braces.

Conditional styling

A great thing about React web applications is that you can dynamically customize the appearance of each element. For example, if a user enters wrong value into the email field, change the color of input element to red and highlight the error.

In React, you can use expressions like ternary operators to set up a condition and dynamically return one class value or another. This is the best approach for setting an inline expression that generates a dynamic class value. The process is better described in this tutorial on setting conditional className values in React.
Alternatively, you can create a condition outside of JSX. This is better, because you can’t use statements like if, case or a for loop within JSX. You can set a much more complex condition outside of it.

External libraries

React community has created various libraries for handling common styling tasks in React. For instance, the classnames package provides a function of the same name, used for dynamically applying class values.
There is also a popular styled-components package, which can help you create local CSS rules for components. It is commonly used in development of large scale web applications. You will often find that the knowledge of this package is necessary to get a job.

Top comments (22)

Collapse
 
quantumcompliance profile image
Quantum Compliance

Incident management software is a specialized tool designed to help organizations effectively track, manage, and resolve workplace incidents, accidents, and near misses. This software streamlines the entire incident reporting process, allowing employees to quickly log incidents through user-friendly interfaces, often accessible via mobile devices. Key features typically include automated workflows for incident reporting and investigation, customizable templates for incident forms, and real-time notifications to ensure prompt response. Additionally, the software often includes analytics and reporting tools that help organizations identify trends, assess risks, and implement preventive measures. By centralizing incident data and facilitating communication among teams, incident management software enhances safety culture, reduces response times, and ultimately helps organizations improve their overall safety performance and compliance.

Collapse
 
tomdanny profile image
Tom Danny

Explore various methods for designing apps in React with exclusive insights from Wowdeals Dubai. Delve into the diverse approaches and techniques used by developers to create intuitive and visually appealing applications. From component-based design to state management strategies, discover the versatility of React for building modern web and mobile apps. Stay informed about the latest trends and practices in app design, and unlock the potential of React for your next project with Wowdeals Dubai.

Collapse
 
medianet7070 profile image
Media Net

Download Inat Box Pro APK for Android and dive into the world of free movies, TV shows, series and anime! Inat Box TV APK is your ultimate alternative to Netflix, Prime, Hulu and other streaming giants.

Collapse
 
medianet7070 profile image
Media Net

Rope Hero Mod APK is a popular 3D open-world action game where players control a superhero with extraordinary rope-swinging abilities, like a cross between Spider-Man and a vigilante ropeheromodapk.online/.

Collapse
 
medianet7070 profile image
Media Net

Can we use filter system in our normal blog  to pick up the latest new or article on the top if the user want it? Kindly guide me regarding this. Freecine offers an ad-free streaming experience, allowing users to enjoy their favorite movies and TV shows without interruptions. This feature enhances the viewing experience, providing seamless and uninterrupted entertainment for users who value quality and convenience. freecine.click

Collapse
 
medianet7070 profile image
Media Net

Discover Spotify Premium APK 2025 to unlock ad-free music, offline listening, and more without spending a dime. Start streaming your favorites. PPSSPP Gold is a popular emulator for Android devices that allows you to run games and other popular ROMs on Android devices via the downloaded ISO and CSO ROM files.

Collapse
 
medianet7070 profile image
Media Net

Alight Motion Mod APK is one of the first professional motion graphics apps for your mobile phone, which offers the most qualitative features. Mainly, Alight Motion app offers professional quality motion graphics, animation, visual effects, video compositing, and video editing.

Collapse
 
medianet7070 profile image
Media Net

Cinegato is a movie and web series streaming app that offers premium services and access to high-quality videos at low prices. Here you can download the latest version of Cinegato APK that works great on Android, Smart TV and computers.

Collapse
 
medianet7070 profile image
Media Net

Can we use filter system in our normal blog  to pick up the latest new or article on the top if the user want it? Kindly guide me regarding this. Freecine offers an ad-free streaming experience, allowing users to enjoy their favorite movies and TV shows without interruptions. This feature enhances the overall viewing experience, providing seamless and uninterrupted entertainment for users who value quality and convenience.

Collapse
 
medianet7070 profile image
Media Net

Castle App offers an ad-free streaming experience, allowing users to enjoy their favorite movies and TV shows without interruptions. This feature enhances the overall viewing experience, providing seamless and uninterrupted entertainment for users who value quality and convenience.