Yes, you can zoom the editor in VS Code with the mouse wheel. There are two straightforward ways to do this.
Update your settings file.
Manually go through the settings and update the appropriate value.
Updating Your Settings
The first method to allowing VS Code to zoom the editor with the mouse wheel starts by going to the VS Code settings page. You can get here through the top menu or the keyboard shortcut command – CMD + , on macOS or CTL + on Windows.
Once you are in the settings menu, you need to either scroll down or search
for the following option:
Once you click the check box, you should be good to go.
Updating The Settings File
The other way to enforce this functionality is to directly update the settings JSON file. Follow the VS Code to settings in this link to find the settings.json file.
Once there, you need to add the following key/value pair:
"editor.mouseWheelZoom": true
Conclusions
Now you know how to enable mouse wheel zooming in VS Code. You can see how the editor can be tailored to your work style. The settings file contains several features not enabled by default and some you don’t want to be enabled by default.
Thanks for reading! Don’t forget to contact me with any questions or suggestions on Twitter or check out my React, Recoil or MUI articles!
In our previous article, we introduced Recoil to our app. In this article, we’ll add a more complex piece of state, an array of live games currently underway. We’ll also add a button to add new games to our list.
Creating The Atom
The first step is to create an atom that will hold the state of the current games. The games will be stored in an array, with each element containing a high-level overview of the game details.
The details we are storing are as follows:
the id of the game
the name of the table
the number of players currently playing
The time the table has been active.
Of the above values, we will not be displaying the id value. We can use this id as the key for our table in React.
We begin by creating a folder that will be used to hold Recoil Atoms. This folder is named state for the time being. In this folder, we will create a file named LiveGamesState.js. This file will contain one exported value named liveGamesState.
Using the atom() function from the Recoil package, we can create our array and export it for use by other components. The default value is set to include five made-up tables. This will do for now, as we are just using this to demonstrate using state in our application.
The LiveGameState.js File
The following is the result of the above considerations when generating an Atom for the live games:
Our LiveGamesTable component currently displays the live games in a table. It uses a seed function to create five rows to use as sample data.
Let’s replace this seed function and use our newly minted Atom as the data source for the table.
//const data = generateTablesData(5);
const data = useRecoilValue(liveGamesState);
That is all required (other than importing useRecoilValue from recoil). If you run the application at this stage, you will see no difference from what we had in the previous article.
Updating The Atom
Now we can read the data in the LiveGamesState Recoil state. The next step is to be able to add new games to the list.
Let’s create a button in the NavBar that will add new games to our list.
Note: The addGame function will keep adding the same data to the table. This means that React will complain about the same key being used multiple times in the table. This is OK for now.
Running the app with this button enabled looks like this:
Conclusion
As demonstrated, we can add complex state objects to our application with just a few lines of code. Recoil makes global state management easy to understand and implement.
Don’t forget to look at our other MUI and React articles!
Tree shaking is a technique used in computer programming, particularly in the context of modern JavaScript bundlers and compilers, to eliminate unused or “dead” code from the final output bundle or executable.
The goal is to optimize the size and performance of the resulting code by removing portions of the code that are not used in the application, thereby reducing the overall footprint of the software.
Tree shaking works by analyzing the static code dependencies of an application and identifying portions of the code that are not reachable from the entry point or are not used in any meaningful way. These unused code segments are eliminated during the build process. This results in a smaller output bundle containing only the code necessary for the application to function correctly.
This can result in faster load times, reduced bandwidth usage, and improved runtime performance. Tree shaking relies on modern JavaScript language features such as ES6 modules, which allow for static analysis of imports and exports, and a build tool or a bundler that supports tree shaking, such as Webpack or Rollup.
Additionally, developers need to write code modular and optimized manner. Using clearly defined imports and exports enables effective tree shaking.
Overall, this is an important optimization technique in modern web development workflows. It helps to reduce the size and improve the performance of JavaScript applications, resulting in a better user experience.
A Tree Shaking Example
Let’s look at a concrete example of this in JavaScript.
If we had a file that contained four string functions:
When we bundle app.js with a tree-shaking-enabled bundler, the unused functions toUpper and toLower from the math.js module will be eliminated from the final bundle, resulting in a smaller and more efficient JavaScript bundle with only the used functions concat and substr.
Thanks for reading! Don’t forget to check out our articles on React here or to chase me down on Twitter
Continuing from the last article, we are at a point where we want to build the components that a logged-in user can see. But we don’t want to start adding complex authentication handling to our application yet. This can be done by adding global state management system like Recoil to our application.
Introducing Recoil
Recoil is the state management library built by the Meta (Facebook) team. In the Card Games app, we’ll implement Recoil to manage the logged-in status of our users and some details about the games currently being played.
Considering it is still reasonably new (2020) to the public, you may prefer to use another tool for your applications.
Setting Up State With Recoil In Our App
To begin, we need to install Recoil:
npm install recoil
Once installed, we must wrap our application component with the Recoil component. This allows Recoil to be present on all child components. The Recoil wrapping component is called RecoilRoot.
Let’s start with a simple boolean value to denote whether a user is logged in. In Recoil, this will be done by creating an Atom. An Atom represents state in Recoil.
To create an Atom, you call the atom() function and pass a JSON value as the parameter. For example, our logged-in state can be represented as an atom like this:
import { atom } from 'recoil';
const loggedInState = atom({
key: 'loggedInState',
default: false,
});
Now that we have the loggedInState Atom ready to go, we need two more parts to make the Atom useful:
a way to read the current value of loggedInState
a way to update/set the value of loggedInState
Reading The Value Of A Recoil Atom
Use the hook useRecoilValue to retrieve an Atom’s value and subscribe your component to re-render if the value changes.
If we continue with our loggedInState Atom from above, you can get access to its value like this:
const loggedIn = useRecoilValue(loggedInState);
You can then use the variable loggedIn within your component to drive the UI.
Setting The Value Of A Recoil Atom
Setting the Atoms value is also done by using a hook. This hook is called useRecoilState. This hook will return the state value and the function to set the state value. Much like the useState hook does in React.
Let’s update our above example using the useRecoilState hook:
That is all that we need to do to save the logged-in status of our users. Let’s look at hiding the currently played games table for users that aren’t logged in.
Using Recoil Atoms In Other Components
We have a component:
<LiveGamesTable />
This component lists all the games that are currently happening. I will show this table when a user logs in.
Luckily, we now have an Atom that holds the logged-in status of users.
Let’s use this status to hide or show the table as appropriate.
Remembering the hooks mentioned above, our LiveGamesTable component must use the useRecoilValue hook to ascertain the users logged in status.
So, let’s start by importing what we need into the LiveGamesTable component:
import { useRecoilValue } from 'recoil';
import { loggedInState } from './App';
We now need to get the logged-in value from the loggedInState Atom. We can put this at the start of the LiveGamesTable function for use later:
function LiveGamesTable() {
const loggedInStatus = useRecoilValue(loggedInState);
And finally, we can do a boolean shortcut to only display the table to logged-in users:
{loggedInStatus &&
<Box...
And there you have it. We now have a scaffold for adding global state to our application. In the next article, I will add a more complex data structure (the details of the games currently being played) to the global state.
Thanks for reading! If you want to catch up with me directly, reach out on Twitter. And as always, you can find the source code on GitHub
P.S. You can see where this project started in my other article here
In this article, we’ll customise the look and feel of the MUI Card Game site that we started previously. The process of theming a site using MUI involves two main steps:
Create a theme object
Wrap components with ThemeProvider that you want to use for your theme.
This tells us how to create a theme, but what kind of customisations should you look at when designing your theme?
Theme Considerations
The three most important considerations (according to me) when setting up a theme in MUI are:
Colours
Spacing
Typography
Colours
MUI works off primary and secondary colours. Setting primary and secondary colours in MUI can help personalize your site and make it more engaging and accessible to your users. It’s important to choose colours that suit your brand, content, and target audience and ensure that the colours are consistent across all your site’s components.
Spacing
Using a consistent spacing scheme across your site, you can personalise the site to your brand or aesthetic. Spacing can also help with accessibility issues. For example, if your buttons have sufficient space between them, it is easy for users to click the correct button.
Typography
Typography is really important when styling your theme. Using the same typography across your site can help with branding and aesthetics.
With these considerations in mind, let’s consider creating the theme in MUI.
Creating A Theme Object In MUI
To set a theme across your site in MUI, you must create a theme object that you wrap around your root component with a ThemeProvider component.
You can then export the theme object to wrap around other components in your application (in this case, we’ll wrap the entire site in our custom theme).
The Theme Properties
I will set the site’s typography, spacing and colours for this example. The documentation on how to set a custom theme can be found here.
Spacing
For this theme, I want to make it compact, as the plan for the site has tables of games being played online, user stats and more. So screen real estate is at a premium in most views.
We add a spacing key/value pair, with a value less than 8, to the JSON theme to make the site more compact. The reason it’s set to less than 8 because the default theme layout spacing value in MUI is 8.
Colours
I have picked two colours, green and red, as my primary and secondary colours, respectively. For the primary,I will use #386641, and for the secondary, I will use #bc4749.
These colours should hopefully help give the site the feel of a casino. The best part is that we change the theme colours later, and the site will update accordingly.
Typography
I want to use a clean, easy-to-read font, so I have chosen the font Lato for this purpose (with a fall back to sans-serif).
Coding The MUI Theme
Now that we’ve decided on how we want the overall theme to look, we create the JSON object that will be the source of our theme.
The JSON is fairly self-explanatory. We are setting the colours in the pallet. Spacing is set on the base level, as is typography. With just a few lines of JSON, we can now style our entire site without adding classes to each component to perform the styling.
MUI Component Styling
In addition to the above styling, you can style MUI components to your liking. To demonstrate this, we’ll now add a components element to our JSON data that will stripe alternating rows of MuiTableRow instances, colour the head of the table and add a custom bottom border to each row.
The official MUI documentation lets you learn about the component API and possible theme settings.
How it looks with our theme
As you can see, it’s a pretty basic site, but it shows the main theme settings we’ve applied. The two buttons under the table use colours primary and secondary. The table demonstrates the row striping and bottom border that we’ve applied.
To contrast, let’s remove the ThemeProvider token and look at the same site.
As you can see, the spacing between the buttons is larger, the table is plain, and the default colour scheme has been reverted. Even the small customisation our theme provides makes a big difference already.
Conclusion
Thank you for reading this post on theming with MUI. If you like what you’ve read or want to discuss anything, you can find me on Twitter.
The Box component in MUI differs from a div in that it is a React component that can take the sx prop to access the MUI system properties. This article will compare the MUI Box vs HTML div.
Let’s start with the MUI documentation description of the Box component:
The Box component serves as a wrapper component for most of the CSS utility needs.
https://mui.com/material-ui/react-box/
We can easily understand that a wrapper component drives styling or overarching information down to child components. The difficulty in this description is understanding the “CSS utility needs“.
But first, let’s look at what the Box component outputs in HTML.
What HTML Does Box Output?
To understand the CSS utility needs, it’s important to understand what Box components output when rendering. Let’s start with a simple example:
<Box>Some text</Box
Outputs:
<div class="MuiBox-root css-0">Some text</div>
The Box component outputs a div but sets the class to MuiBox-root. This means that all styling will come from MUI for the elements contained within our Box. This is the first part of CSS utility needs
MUI System Style Functions
If you read further, the documentation mentions that:
The Box component packages all the style functions that are exposed in @mui/system.
An example of a style function is bgColor. This is a shorthand version of the background-color CSS property. The following code is a good example of using bgColor. Notice that we use this style function within the sx prop.
<Box sx={{ bgcolor: "red" }}>Text with red background</Box>
Using Theme Mapping With The MUI Box Component
The biggest benefit of using the Box component, at least in my opinion, is the access to the theme mapping. This allows the developer to access theme options like palette or spacing. Here is a quick example showing how to use these theme options with the box component.
<Box sx={{ bgcolor: 'info.light', p: 5 }}>Text with blue background</Box>
The above code uses the palette setting of info.light, the blue we see above. The p: 5 sets the padding element to 5, as shown in the space around the text in the image above.
The image below shows the theme properties tree where we select the info.light property.
Tree item showing the info light property of the default theme
It’s worthwhile looking at the default theme options in the documentation. It can be found here.
The alternative way to get a standard div to access the system properties would be to import them into your file and use the variables to drive the styling. The above method circumvents the need for all that and can focus on your design.
Conclusion
There is not much more to the Box component than this. It allows you to wrap your elements so that they inherit the MUI theme, as well as allowing you to select directly from the system properties. Hopefully, this helps you understand the MUI Box vs HTML div.
In this article, I will attempt to refactor the PlayingCard component that we built in this article. The refactor will convert the component from plain React to MUI. Once we’ve updated the card, we can import this into our Card Game app and use it as the base playing card for each game.
If you’re looking for the final product, you can find it on GitHub here.
Looking at the final PlayingCard component, we can make a few obvious updates.
The first visual change will be the drop shadows that give the card thickness. MUI offers the paper container property that will give a nice paper feel to our card.
Using The Paper Property
In our PlayingCard component, the card was represented by a div element. Let’s change this to a Paper component. We must replace the opening and ending tags from div to Paper.
Once we’ve updated the tags, we must remove the box shadow style property.
If we were to run the code at this point, you would see the playing card with no shadows looking the same as it did before. This is what we want to see.
Using the elevation attribute, we can recreate the complex box shadow styling we removed earlier. The elevation attribute is an integer (number) from 0-24. 24 is the highest elevation we can give our paper component. Let’s add this to our card now. The Paper component in our code now looks like this:
The next alteration we can make is using Typography instead of standard HTML text elements. We start by making sure we are importing the Roboto font. Following the instructions in the Typography documentation, we need to install the @fontsource/roboto NPM package.
npm install @fontsource/roboto
Once we’ve installed roboto, we update the h1 elements and replace them with Typography components. For example, our top h1 tag becomes:
Finally, we can update the div containers in the PlayingCard component to use the MUI Box component instead. After replacing all divs with Boxes, we can update the style attributes to use the MUI sx prop.
And that should do it for now. We’ve taken a plain React component and applied MUI fundamental components. This may not seem like a big deal, but it might become bigger once we start theming our card game site.
In this article, we’ll build a basic UI for a card game (remember the playing card component we built earlier) using React with MUI Core. This UI will showcase the following:
In short, MUI core is a set of React components that can be used as the foundation blocks of your design system. Furthermore, these components have been designed with accessibility always in mind (which is super important).
MUI implement’s Googles material design.
We will follow the instructions from the MUI website to start building our application, but first, we’ll need to create the base application. For this, we can use the create-react-app script for bootstrapping a basic React app that we will then style using MUI Core.
Creating The React App Using create-react-app
npx create-react-app mui-card-game
This will create a directory with our React app ready to configure.
Installing MUI Core
Installing MUI core is done by using npm as follows:
Because MUI uses the Roboto font, we must import it into our application. We start by installing @fontsource/roboto:
npm install @fontsource/roboto
Once you’ve installed Roboto, we must import the fonts at our app’s entry point. Because we are using create-react-app, our entry point will be in src/index.js. You need to add the following to add all the variations of Roboto that MUI uses:
With material, emotion and Roboto now configured for our application, we must add Icons. This is another npm package.
npm install @mui/icons-material
Cleaning Up create-react-app
Lastly, we need to remove any styling with create-react-app in our setup. This is done by removing the two CSS files in the src folder: index.css and App.css, and references to these files.
InApp.js, remove the following line:
import './App.css';
And in index.js, remove this line:
import './index.css';
If you start the site now:
npm start
You will see the React icon with some text underneath (we’ve removed the style sheets, so the result won’t look good):
create-react-app with styling removed
Next, we can remove the contents of App.js and replace them with our new code.
Adding A NavBar With React and MUI Core
Let’s clear out most of the contents of App.js, so we are left with this:
In MUI, you must add an AppBar that will act as our NavBar. The easiest way to get started is to head over to the MUI documentation for AppBar and grab the closest example to what we need. For this demo we can select the basic AppBar example.
If you copy the code, we can create a new component in our app in a new file called NavBar.js. Populate this file with the below code (The only difference from the MUI documentation is that I have renamed the function name to NavBar):
import * as React from 'react';
import AppBar from '@mui/material/AppBar';
import Box from '@mui/material/Box';
import Toolbar from '@mui/material/Toolbar';
import Typography from '@mui/material/Typography';
import Button from '@mui/material/Button';
import IconButton from '@mui/material/IconButton';
import MenuIcon from '@mui/icons-material/Menu';
export default function NavBar() {
return (
<Box sx={{ flexGrow: 1 }}>
<AppBar position="static">
<Toolbar>
<IconButton
size="large"
edge="start"
color="inherit"
aria-label="menu"
sx={{ mr: 2 }}
>
<MenuIcon />
</IconButton>
<Typography variant="h6" component="div" sx={{ flexGrow: 1 }}>
News
</Typography>
<Button color="inherit">Login</Button>
</Toolbar>
</AppBar>
</Box>
);
}
Installing Dependencies
To use the above code, you’ll need to install @mui/icons-material NPM package:
npm install @mui/icons-material
In App.js, import the NavBar component and render this component in the return statement as follows:
import NavBar from "./NavBar";
function App() {
return <NavBar />;
}
export default App;
If we run the code, we will see the AppBar looking like this:
Basic AppBar (from MUI documentation)
Let’s tweak the navbar to have a sign up button and to change the text News to Card Games:
import * as React from 'react';
import AppBar from '@mui/material/AppBar';
import Box from '@mui/material/Box';
import Toolbar from '@mui/material/Toolbar';
import Typography from '@mui/material/Typography';
import Button from '@mui/material/Button';
import IconButton from '@mui/material/IconButton';
import MenuIcon from '@mui/icons-material/Menu';
export default function NavBar() {
return (
<Box sx={{ flexGrow: 1 }}>
<AppBar position="static">
<Toolbar>
<IconButton
size="large"
edge="start"
color="inherit"
aria-label="menu"
sx={{ mr: 2 }}
>
<MenuIcon />
</IconButton>
<Typography variant="h6" component="div" sx={{ flexGrow: 1 }}>
Card Games
</Typography>
<Button color="inherit">Login</Button>
<Button color="inherit" variant="outlined">Sign Up</Button>
</Toolbar>
</AppBar>
</Box>
);
}
Updated AppBar
We need to add a signup form to our site. Let’s do this using a modal form where users can enter their email addresses and password. The easiest way is to return to the MUI documentation and find the modal examples.
When we search for Modal in the documentation, you will see a note saying that if you want to use a modal component, you probably want to use the Dialog component. So based on this, we’ll move forward using the Dialog component.
In the documentation for Dialog, there is an example of a Form Dialog. Let’s use this as our base for the signup form. We’ll call our component SignUpForm and put it in a file named SignUpForm.js
import * as React from 'react';
import Button from '@mui/material/Button';
import TextField from '@mui/material/TextField';
import Dialog from '@mui/material/Dialog';
import DialogActions from '@mui/material/DialogActions';
import DialogContent from '@mui/material/DialogContent';
import DialogContentText from '@mui/material/DialogContentText';
import DialogTitle from '@mui/material/DialogTitle';
export default function SignUpForm() {
const [open, setOpen] = React.useState(false);
const handleClickOpen = () => {
setOpen(true);
};
const handleClose = () => {
setOpen(false);
};
return (
<div>
<Button color="inherit" variant="outlined" onClick={handleClickOpen}>
Open form dialog
</Button>
<Dialog open={open} onClose={handleClose}>
<DialogTitle>Subscribe</DialogTitle>
<DialogContent>
<DialogContentText>
To subscribe to this website, please enter your email address here. We
will send updates occasionally.
</DialogContentText>
<TextField
autoFocus
margin="dense"
id="name"
label="Email Address"
type="email"
fullWidth
variant="standard"
/>
</DialogContent>
<DialogActions>
<Button onClick={handleClose}>Cancel</Button>
<Button onClick={handleClose}>Subscribe</Button>
</DialogActions>
</Dialog>
</div>
);
}
There are two notable differences between the sample code and the code above. This ensures the button inherits the colour from its parent and the component’s name. The highlighted line shows these differences.
Adding The Dialog To The NavBar
Now we have a button component displaying a modal form for the user to enter an email address. The next thing to do is to add the component to the NavBar. We’ll replace the current Sign Up button we placed earlier.
import * as React from 'react';
import AppBar from '@mui/material/AppBar';
import Box from '@mui/material/Box';
import Toolbar from '@mui/material/Toolbar';
import Typography from '@mui/material/Typography';
import Button from '@mui/material/Button';
import IconButton from '@mui/material/IconButton';
import MenuIcon from '@mui/icons-material/Menu';
import SignUpForm from './SignUpForm';
export default function NavBar() {
return (
<Box sx={{ flexGrow: 1 }}>
<AppBar position="static">
<Toolbar>
<IconButton
size="large"
edge="start"
color="inherit"
aria-label="menu"
sx={{ mr: 2 }}
>
<MenuIcon />
</IconButton>
<Typography variant="h6" component="div" sx={{ flexGrow: 1 }}>
Card Games
</Typography>
<SignUpForm />
<Button color="inherit">Login</Button>
</Toolbar>
</AppBar>
</Box>
);
}
Now when we click the Sign-Up button, we’ll see the following:
Subscribe Dialog
We can tweak the contents of the Dialog for our needs. We want:
Users to sign up and not subscribe
To get users’ names when signing up.
Therefore we need more form fields in the Dialog and change some of the text.
Let’s look at the code of our SignUpForm component now that we’ve updated the text and fields.
import * as React from 'react';
import Button from '@mui/material/Button';
import TextField from '@mui/material/TextField';
import Dialog from '@mui/material/Dialog';
import DialogActions from '@mui/material/DialogActions';
import DialogContent from '@mui/material/DialogContent';
import DialogContentText from '@mui/material/DialogContentText';
import DialogTitle from '@mui/material/DialogTitle';
export default function SignUpForm() {
const [open, setOpen] = React.useState(false);
const handleClickOpen = () => {
setOpen(true);
};
const handleClose = () => {
setOpen(false);
};
return (
<div>
<Button color="inherit" variant="outlined" onClick={handleClickOpen}>
Sign Up
</Button>
<Dialog open={open} onClose={handleClose}>
<DialogTitle>Sign Up</DialogTitle>
<DialogContent>
<DialogContentText>
To sign up to this website, please enter your personal details here.
</DialogContentText>
<TextField
autoFocus
margin="dense"
id="email"
label="Email Address"
type="email"
fullWidth
variant="standard"
/>
<TextField
autoFocus
margin="dense"
id="name"
label="Full Name"
type="text"
fullWidth
variant="standard"
/>
</DialogContent>
<DialogActions>
<Button onClick={handleClose}>Cancel</Button>
<Button onClick={handleClose}>Sign Up</Button>
</DialogActions>
</Dialog>
</div>
);
}
As you can see, there is now another text field for users to enter their full names into. We’ve also altered the description a little to suit our needs. The output of the above code looks like this:
Sign Up Dialog
Creating The Current Games Table
Now that we have completed the faux login button and signup form, we will add a table showing a list of all the current games currently being played online. We will use dummy data to populate the table to show how easy it is to get a decent-looking table going with MUI.
The table structure is simple in MUI. Here is the code that will build a table:
In the above code, I’ve used the component type to be paper for styling purposes. The rest of the code resembles an HTML table quite closely.
In the table body section, I used an array and mapped out each row based on each element in the array. The resulting table looks like this:
Current Games Table
Putting It All Together
Now that we have our header and table, we can look at the entire page as a whole:
The following image shows the site after the signup button is clicked:
After the Sign Up button clicked
Conclusion
With just a little bit of customisation, we’ve generated a basic page structure with MUI that looks professional and is accessibility friendly. This goes to show how powerful using a UI framework can be. It also shows how well React and MUI Core work together. Thanks for reading!
This is a library for managing state in JavaScript applications. It helps you keep track of changes to your data and automatically updates your user interface when those changes occur.
Think of it like a magic assistant sitting in your code and watching everything happening. Whenever something changes, it waves its wand and updates your app accordingly. You don’t have to worry about manually updating the interface or keeping track of all the different pieces of data. MobX takes care of it for you.
This makes it much easier to build complex applications. Because you can focus on writing the code that makes your app work. Rather than worrying about the plumbing that connects everything. With MobX, you can create reactive, responsive apps that feel snappy and fast.Eeven when dealing with large amounts of data.
Also known as Material-UI, this is a popular open-source UI component library for React based on Google’s Material Design principles. Providing pre-built and customizable UI components such as buttons, forms, icons, typography, and more. Developers can use these to quickly build modern and visually appealing web applications.
It follows a component-based architecture, allowing developers to easily create reusable and composable UI components. It also provides theming support, allowing developers to customize the look and feel of their applications. This is done by defining their colour palette, typography, and other design elements.
MUI Core is widely used in the React community and has a large and active community of contributors. It is continuously updated and improved, with new features and components regularly added. Licensed under the MIT License, making it free to use and modify in commercial and non-commercial projects.
A popular CSS-in-JS library for React that allows developers to write CSS code inside their React components. It provides a way to style components more modularly and reusable way. The styles are encapsulated within the component. Therefore they don’t affect other components of the application.
This library allows developers to define styles as JavaScript functions or tagged template literals. These styles are then applied to the corresponding components using a higher-order component (HOC) or a styled component factory function. This makes it easy to create responsive and dynamic styles based on props or state.
It also supports server-side rendering, theming, and automatic vendor prefixing. Making it a versatile and powerful tool for styling React components.
One of the advantages of using this is that it allows developers to write CSS in a more maintainable way. By keeping styling close to the components they style, it becomes easier to reason about how style changes will affect the component and its children. Additionally, this library allows developers to use all the power of JavaScript to create dynamic and complex styles. This makes it a very flexible and powerful tool for building modern web applications.
Could you think of how styled components could be used in our Card component?
React Icons is a popular open-source library that provides a set of customizable icons for use in React applications. It offers a wide range of icons from popular icon sets such as FontAwesome, Material Design, and Ionicons, as well as custom-designed icons.
React Icons provides a simple and flexible API that allows developers to add icons to their components easily. It supports multiple sizes, colours, and styles for each icon and provides different ways to import and use icons depending on the developer’s preferences.
Some of the advantages of using React Icons include the following:
Customizable: React Icons provides a simple and flexible way to customize icons by changing their size, colour, and style.
Easy to use: The library provides a straightforward API that makes adding icons to React components easy.
Lightweight: The library is lightweight and does not require any additional dependencies.
Widely used: React Icons is a popular library with a large and active community of contributors. Making it a reliable and well-maintained option for adding icons to React applications.
Summing up, React Icons is a great tool for developers who need to add icons to their React applications in a flexible and customizable way.
React Query is a popular open-source library for managing server-state and fetching data in React applications. It offers a simple and intuitive API for data fetching, caching, and synchronization, making handling complex data requirements in your React components easier.
React Query offers key features that make it a powerful tool for managing data in your React applications. In particular, these include:
Query caching: React Query automatically caches your API responses. This can improve the performance of your application and reduce the number of network requests.
Data synchronization: React Query provides built-in support for real-time polling, and optimistic updates, making it easier to keep your application in sync with your backend.
Error handling: React Query offers robust error handling, built-in support for retrying failed requests, handling stale data, and more.
Pagination and infinite scrolling: React Query provides built-in support for pagination and infinite scrolling, making it easy to handle large data sets.
Overall, React Query simplifies data fetching and management in React applications, helping developers to build more performant and reliable user interfaces.
React Table is a popular open-source library for building data tables in React applications. It provides a flexible and customizable API for rendering tables with large amounts of data, allowing developers to create powerful and performant user interfaces.
Some of the key features of React Table include:
Sorting and filtering: React Table provides built-in support for sorting and filtering data, making it easy to display large data sets meaningfully.
Pagination: React Table supports pagination, allowing you to display data in smaller, more manageable chunks.
Row selection: React Table supports row selection, making implementing features like bulk actions and editing easy.
Custom rendering: React Table provides a powerful API for customizing your table cells, headers, and more rendering.
Server-side rendering: React Table supports server-side rendering, allowing you to render your tables on the server and send the HTML to the client for improved performance and accessibility.
Evidently, React Table is highly customizable and extensible, making it a popular choice for building data tables in React applications. It is also compatible with various data sources, including JSON, CSV, and REST APIs.
Create React App (CRA) is an open-source tool created by Facebook for setting up a modern React application with zero build configuration. It provides a simple and streamlined way to create and manage a new React project, allowing developers to focus on building their applications instead of worrying about tooling and configuration.
Create React App sets up a development environment for React that includes many of the commonly-used tools and technologies, such as:
Webpack: A module bundler that helps to bundle all of the assets, including JavaScript files, CSS files, and images.
Babel: A JavaScript compiler that allows developers to write modern JavaScript code and transpile it to be compatible with older browsers.
ESLint: A linter that helps to enforce code quality and consistency.
Jest: A testing framework that provides a simple and easy-to-use API for testing React components and JavaScript code.
Hot Module Replacement: A feature that allows developers to see the changes they make in real-time without manually refreshing the browser.
Create React App also provides several configuration options, allowing developers to customize their development environment to suit their needs. It supports CSS modules, environment variables, code splitting, and more.
Overall, Create React App is a powerful tool that makes it easy to set up a new React project with minimal configuration, allowing developers to focus on building their applications instead of managing tooling and configuration.
React Motion is a popular open-source library for building animated user interfaces in React applications. It provides a simple and intuitive API for creating complex animations and interactions, allowing developers to create fluid and engaging user experiences.
React Motion is based on the principles of physics-based animation, which means that a set of parameters such as velocity, acceleration, and damping drives animations. This approach allows for more natural and realistic animations that respond to user input and change over time.
Some of the key features of React Motion include:
Spring-based animations: React Motion provides a simple and powerful API for creating spring-based animations, which can be used to animate everything from simple transitions to complex interactions.
Customizable animation parameters: React Motion allows developers to customize the parameters of their animations, including things like spring stiffness, damping, and velocity.
Performance optimizations: React Motion is designed to be highly performant, with features like batched updates and optimized rendering to minimize the impact on the user interface.
Easy integration with React: React Motion is designed to work seamlessly with React, allowing developers to build complex animations and interactions using the same familiar API and programming model.
Overall, React Motion is a powerful tool for building animated user interfaces in React applications, allowing developers to create engaging and interactive experiences that respond to user input and change over time.
Enzyme is a popular open-source JavaScript testing utility created by Airbnb for testing React components. It provides a set of intuitive and flexible APIs for testing React components’ behaviour and state changes, making it easy to write comprehensive and reliable tests for React applications.
Enzyme offers several features that make it a powerful tool for testing React components, including:
Shallow rendering: Enzyme provides a shallow rendering API that allows developers to test a component in isolation without rendering its child components.
Full DOM rendering: Enzyme also provides a full DOM rendering API that allows developers to test a component in the context of its parent and child components.
Powerful selectors: Enzyme provides a set of powerful selectors that allow developers to find and manipulate components within their tests easily.
Snapshot testing: Enzyme supports snapshot testing, allowing developers to easily capture the output of a component and compare it against a previously saved snapshot.
Easy integration with other testing frameworks: Enzyme can be easily integrated with others like Jest, Mocha, and Chai, making it a versatile and flexible tool for testing React applications.
Enzyme is a powerful testing utility that makes writing comprehensive and reliable tests for React components easy. Its intuitive and flexible API, along with its support for shallow rendering, full DOM rendering, and snapshot testing makes it a popular choice among developers for testing React applications.
A popular open-source framework for building server-side rendered React applications. It provides features and conventions for building modern web applications, including automatic code splitting, server-side rendering, and static site generation.
Some of the key features of Next.js include:
Server-side rendering: Next.js provides built-in support for server-side rendering, allowing your application to render on the server and send HTML to the client for improved performance and SEO.
Automatic code splitting: Next.js automatically splits your code into smaller chunks, allowing your application to load faster and improve performance.
Static site generation: Next.js allows you to generate a static version of your application, making it easy to deploy to a static hosting provider like Netlify or GitHub Pages.
File-based routing: Next.js provides a simple and intuitive file-based routing system that makes creating pages and routes in your application easy.
API routes: Next.js provides a built-in API route system, making creating API endpoints in your application easy.
CSS-in-JS support: Next.js provides built-in support for popular CSS-in-JS libraries like styled-components and emotion, making creating dynamic and responsive styles in your application easy.
All in all, Next.js is a powerful and versatile framework for building modern web applications. Its built-in support for server-side rendering, automatic code splitting, static site generation, intuitive file-based routing system, and support for popular CSS-in-JS libraries make it a popular choice for building scalable and performant React applications.
Conclusion
This list is not meant to be an exhaustive list of must-know React packages, but React developers need to understand the type of packages available. If this list has helped you, please share the article! Thanks for reading!
If you have tried to write your React components without a local web server, you may have encountered an issue where the React dev tools cannot access local files.
In these instances, there won’t be an error in your console, but you will see a message like the following:
Download the React DevTools for a better development experience: https://reactjs.org/link/react-devtoolsYou might need to use a local HTTP server (instead of file://): https://reactjs.org/link/react-devtools-faq
To get the React Dev Tools working with local files, you need to allow the extension to have access to them. This is done in the Manage Extension section of the developer tools. You can access this by clicking the three vertical dots (vertical ellipsis?) next to the extension name. You will get a drop-down menu like the one below where you can click the Manage Extension menu item.
Once you click this, you will be presented with a list of options for the extension. You are looking for the option Allow Access to file URLs. If you turn this on, you can use the developer tools on local React components.
You can find more information on the React dev tools extension, precisely this issue, here.
Interestingly, in Firefox (on macOS, in my case), I didn’t have to add any permissions to allow the dev tools to work with local files. There is no option to allow dev tools to work with local files, so it seems intentional that it works out of the box with no user feedback required.
Don’t forget to check out some of our other articles on React: