Found 90 Articles for ReactJS

How to use Radium in ReactJS?

Rahul Bansal
Updated on 18-Mar-2021 10:54:55

645 Views

In this article, we are going to see how to apply inline styling to a component in a React application.Radium is a popular third package application used to add inline styling and pseudo selectors such as :hover, :focus, :active, etc. to a JSX element.Installing the modulenpm install --save radiumORyarn add radiumNpm is the node package manager which manages our React package but yarn is the more secure, faster and lightweight package manager.ExampleApp.jsximport Radium from 'radium'; import React from 'react'; function App() {    const style = {       ':hover': {          backgroundColor: '#000',     ... Read More

How to update parent state in ReactJS?

Rahul Bansal
Updated on 18-Mar-2021 10:53:35

3K+ Views

In this article, we are going to see how to update the parent state from a child component in a React application.To update the parent state from the children component, either we can use additional dependencies like Redux or we can use this simple method of passing the state of the parent to the children and handling it accordingly.ExampleIn this example, we will build a React application which takes the state and the method to update it from the parent component and pass it to the children component and after handling it we will pass the updated state to the ... Read More

How to set cookies in ReactJS?

Rahul Bansal
Updated on 10-Sep-2023 08:24:17

30K+ Views

In this chapter, we are going to see how to set, remove and retrieve cookies in a React application.Cookies are the data stored in the form of key-value pairs that are used to store information about the user on their computer by the websites that the users browse and use it to verify them.To set or remove the cookies, we are going to use a third-party dependency of react-cookie.Installing the modulenpm install react-cookieOr, yarn add react-cookieNpm is the node package manager which manages our React package but yarn is the more secure, faster and lightweight package manager.Setting up cookiesIn this ... Read More

Functional Components Vs. Class Components in ReactJS

Rahul Bansal
Updated on 18-Mar-2021 10:47:07

2K+ Views

Functional Components or stateless components are the most widely used type of components with a basic syntax of JavaScript Functions that return the JSX code or the HTML code.They are called as stateless components because they accept the data and display it accordingly and are mainly responsible for the rendering of the UI.Exampleimport React from ‘react’; const App=()=>{    return (                TutorialsPoint          ) } export default AppOutputClass based or stateful Components are the ES6 classes that extend the component class of the react library. They are ... Read More

Form Handling in ReactJS

Rahul Bansal
Updated on 18-Mar-2021 10:41:14

423 Views

In this article, we are going to see how to handle the forms properly in a React application.Handling Forms is one of the most crucial parts needed while building a real-world React application. It is all about taking the inputs from the user, validating it and displaying if there are errors in the data submitted by the user.ExampleIn this example, we will build an Information Page that takes the information from the user, validates it and displays the result accordingly.Here, we have App.js as the parent component of the Details.js component.Details.jsimport React, { useState } from 'react'; const Details ... Read More

Debugging ReactJS applications

Rahul Bansal
Updated on 18-Mar-2021 10:38:17

649 Views

While building a real-world application, the most important thing that a developer should know is how to properly debug the React application. There are many ways to debug our React application and some of the proven methods are explained below −Using Code LinterTools like ESLint help to write better and clean codes, as it follows proper guidelines which prevent errors at the time of developing the codes.Using React Developer ToolsThis tool comes very handy while debugging ReactJS applications, as it allows to navigate through the Component Tree and allows to take a look at the state or the props or ... Read More

Custom Hooks in ReactJS

Rahul Bansal
Updated on 18-Mar-2021 10:36:29

288 Views

In this article, we are going to learn how to define custom hooks in ReactJS.All the rules and usage guidelines are the same as that of the predefined ReactJS hooks like −Call Hooks at the Top LevelCall Hooks from React Functions onlyExampleIn this example, we will build an input validator application that will display some text based on the user-defined conditions in the custom hook.App.jsximport React from 'react'; import useForm from './CustomHook'; const App = () => {    const input = useForm();    return (                   {input.valid ? ... Read More

CSS Loader in ReactJS

Rahul Bansal
Updated on 18-Mar-2021 10:33:47

2K+ Views

In this article, we will learn how to provide dynamic class names to our React application.StepsNpm run ejectThis command will allow us to customize the configurations and the options that were predefined when we run the command of create-react-app. It is a one-sided operation that can’t be undone later on.Change Webpack configurationsWe need to configure the webpack loaders so as to enable css-loader which will then provide dynamic naming to our classes.Set the configurations as −{    test: /\.css$/,    loader: 'style-loader' }, {    test: /\.css$/,    loader: 'css-loader',    query: {       modules: true,     ... Read More

Context API in ReactJS

Rahul Bansal
Updated on 18-Mar-2021 10:33:01

1K+ Views

In this article, we are going to see how to access the data without passing it through every parent component in the class-based component.Context APIs are used to set the global data and this data can now be accessed in any of the children's components without the need to pass it through every parent component.ExampleSuppose there are three components namely, A, B and C. A is the parent component of B and B is the parent component of C. So, our component structure is as follows − A→B→C.We have defined some data in A and want to handle it in ... Read More

Conditional Rendering in ReactJS

Rahul Bansal
Updated on 18-Mar-2021 10:32:01

403 Views

In this article, we are going to see how to conditionally render a component based on some conditions in a React applicationIn ReactJS, we can render only the desired components based on certain given conditions by using the if-else statements or by using the logical && operator of JavaScript. When the provided condition is satisfied, then React will match the UI and update it accordingly.Using if-else conditionsExampleIn this example, we will build a React application that has an App component as a parent component which will conditionally re-render the Form component and update the UI accordingly.App.jsximport React, { useState } ... Read More

Previous 1 ... 5 6 7 8 9
Advertisements