React ensures your user interface stays in sync with the application state by using a technique called re-rendering. During re-renders, React compares the Virtual DOMs and updates the necessary parts of the UI. This process is known as React Reconciliation...
Notes about Redux
Redux is a JavaScript library that can be used with various JavaScript frameworks, including React, Angular, Vue, and Vanilla JS. It serves as a state management tool for handling cross-component or app-wide state.
Types of states
Below are the different types of states that can exist within an application. There are three main types:
1. Local State
Local state pertains to a single component. An example of this would be listening to user input in a field or toggling a “show more details” button. Typically, local state is managed within the component using useState or useReducer.
2. Cross-Component State
Cross-component state impacts multiple components. For instance, managing the open/closed state of a modal overlay. While this can also be managed using useState or useReducer, it often involves passing state between components via props drilling.
3. App-Wide State
App-wide state influences the entire application, such as themes or user authentication status. Similar to cross-component state, this can be managed using useState or useReducer, albeit with the assistance of props drilling.
How to deploy React app in Firebase
A React Single Page Application (SPA) is essentially a static website and can be easily hosted using platforms like Firebase or Netlify.
Understanding React custom Hooks
In React there are several built-in Hooks like `useState`, `useEffect`, and `useContext`. Sometime you need to create your own Hooks for specific purpose like checking user session, fetching data, or showing notifications...
Understanding React Context
Traditionally, you pass information from a parent component to child component via props in React. But data passing through this props drilling can make your code verbose and inconvenient if you have more components in the middle, or if many components in your app need the same information.
Set up a React project with Vite along with Tailwind CSS
Here is the step by step guide to create a React project with Vite.
- Run the command
npm create vitein the command prompt. - Afer the script you will be prompted to enter a project name.
- After entering the project name, Vite will prompt you to select a framework. Select the framework as React.
- After selecting framework, Vite will prompt you to select language type.
- After selecting the language type, Vite will show the message as Scaffolding the project in the location.
- After that you can go to the folder and instruct to install the dependencies with the command
npm install.
And here is the step to install Tailwind CSS as a Vite plugin.
Run the command
npm install tailwindcss @tailwindcss/viteto Installtailwindcssand@tailwindcss/vitevia npm.Add the
@tailwindcss/viteplugin to your Vite configuration.import { defineConfig } from 'vite' import tailwindcss from '@tailwindcss/vite' export default defineConfig({ plugins: [ tailwindcss(), ], })Add an
@import "tailwindcss";to your CSS file that imports Tailwind CSS.After that you can run the project with command
npm run devor whatever command is configured in yourpackage.jsonfile..
References
What is React?
React is an open-source front-end JavaScript library that is used for building user interfaces...
Difference between React and ReactDOM
React and ReactDOM are two distinct libraries that are commonly used together in the development of web applications with React.
React is a JavaScript library focused on building user interfaces. It follows a declarative approach, where developers define what the UI should look like based on the current state of the application. React then efficiently updates and renders components as the state changes. Its design emphasizes flexibility and efficiency, making it a popular choice for developing both web and mobile applications.
ReactDOM, on the other hand, serves as a bridge between React and the DOM (Document Object Model). The DOM is a hierarchical structure representing the HTML content of a web page. ReactDOM provides a set of methods that enable React components to be rendered and updated within the DOM. It ensures that the user interface is synchronized with the underlying HTML structure.
In summary, React is a library for building user interfaces, while ReactDOM handles the interaction with the DOM, rendering React components onto the web page. Although they are often used together, they serve different purposes and can function independently of each other.