Category: React tutorial
-
Filters and Interceptors in Spring Boot
Filters are a fundamental part of the Servlet API. They operate at the servlet level, meaning they intercept requests before they reach your Spring MVC dispatcher servlet (and thus, your Spring controllers) and responses after they leave it. Key Characteristics of Filters: When to Use Filters: Filters are excellent for tasks that need to be…
-
Redux Toolkit
In modern Redux development, managing state and actions can become cumbersome. Traditionally, we would define action types, action creators, and reducers manually. However, with Redux Toolkit, we can simplify this process by using the createSlice function, which allows us to define actions and reducers together in a more concise and manageable way. This tutorial covers…
-
React inline styling
In React, inline styling can be done using two main approaches: using a style object or a function that returns the style object. Let’s explore both. 1. Inline Style as an Object In this approach, you define the styles as a JavaScript object where the keys are the CSS properties in camelCase (rather than hyphenated)…
-
htmlFor in React
In React, htmlFor is used instead of the regular for attribute when defining labels in forms. This change is due to the fact that for is a reserved keyword in JavaScript, and using it in JSX would lead to syntax issues. Why htmlFor? In HTML, you typically associate a <label> with a form element like…
-
Difference Between react and react-dom
react react-dom Why react-dom is separated from react Example: Conclusion
-
How do you access props in attribute quotes?
In React, when you want to access props inside attribute values, you must use curly braces ({}) to embed JavaScript expressions—including prop values—within JSX. Here, name is a prop, and we access it inside the JSX using {name}. Accessing props inside attribute values (in quotes) When setting an attribute using a prop, do not use…
-
React.proptypes.shape
React.PropTypes.shape is used in React to validate the shape of an object prop—that is, to specify what properties the object should have, and what types each property should be. Note: PropTypes is no longer under React.PropTypes in newer React versions. Instead, you must import it from the prop-types package. Example: Validating object shape with PropTypes.shape…
-
Keyed Fragment in React
In React, keyed fragments are a way to assign a key to a React.Fragment, which is useful when rendering a list of fragments inside a loop. What is a Fragment? A Fragment lets you group multiple elements without adding extra nodes to the DOM. It looks like this: This is equivalent to: What is a…
-
Programmatically trigger click event in react
To programmatically trigger a click event in React, you can use the useRef hook to reference a DOM element or component, and then call its .click() method. Here’s a complete example: Example: Programmatically triggering a button click Explanation:
-
Call hook on a condition like button click or input value
In React, hooks must not be called conditionally or inside event handlers directly — they must always be called at the top level of a functional component or inside a custom hook. However, you can use state to control when the effect of a hook should happen. Here’s how to trigger logic in a hook…