![]() |
Strikethrough text is a visual representation often used to denote changes or deleted content within an application. In this article, we will see various techniques to effectively add a strikethrough to Text using ReactJs. Strikethrough text, also referred to as crossed-out or deleted text serves as a formatting style employed to indicate obsolete or irrelevant content within ReactJS applications. Pre-requisitesApproaches Used to Strikethrough On Text In React JS Table of Content Steps to Create a React ApplicationStep 1: Create a react application by using this command npx create-react-app strikethroughapp
Step 2: After creating your project folder, i.e. strikethroughapp, use the following command to navigate to it cd strikethroughapp
Project Structure: Approach 1: Using CSS in React JSCSS is used in this approach to incorporate a strikethrough effect on text. When the “strikethrough” class is applied to completed tasks within a list, such as a to-do list, it triggers the visual indication of a crossed-out line through the text using the “line-through” text-deĀcoration property. This effectively marks the tasks as finished. Example: The given React example deĀmonstrates a component that showcases a list of completed tasks with strikethrough styling. These tasks are stored in an array. The design highlights centered headings in green and includes paragraphs. Further, the list items are both centered and visually enhanced with a strikethrough appearance. App.js file Javascript
Step to run the application: Step 1: To open the application, use the Terminal and enter the command listed below npm start
Output: Approach 2: On Hover Effect Using React StateIn this approach, we will use the React state to create a hover effect. When users hover over text, a state variable toggles, altering the inline style of the text. This manipulation triggers the “line-through” property, creating a strikethrough effect, effectively highlighting the interactive nature of the UI element. Example: The provided React example showcases a component that creates a striking visual effect in the UI. When hovering over a paragraph, it toggles a strikethrough effect. This functionality leverages React’s state and event handling capabilities to monitor changes in the host state. Furthermore, the paragraph is styled with center alignment and a cursor pointer, ensuring an intuitive user experience. App.js Javascript
Output: |
Reffered: https://www.geeksforgeeks.org
Geeks Premier League |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |