From f8172543a98b8a52f0d573644f902e7dbc6fb10b Mon Sep 17 00:00:00 2001 From: Rahul Bhati <79755738+Rahul-7027@users.noreply.github.com> Date: Mon, 12 Feb 2024 21:17:00 +0530 Subject: [PATCH] Update TextForm.js Redue the code --- src/components/TextForm.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/components/TextForm.js b/src/components/TextForm.js index 07549d6..f757689 100644 --- a/src/components/TextForm.js +++ b/src/components/TextForm.js @@ -3,20 +3,23 @@ import React, {useState} from 'react' export default function TextForm(props) { const handleUpClick = ()=>{ - let newText = text.toUpperCase(); - setText(newText) + // let newText = text.toUpperCase(); + // setText(newText) + setText(text.toUpperCase()); props.showAlert("Converted to uppercase!", "success"); } const handleLoClick = ()=>{ - let newText = text.toLowerCase(); - setText(newText) + // let newText = text.toLowerCase(); + // setText(newText) + setText(text.toLowerCase()) props.showAlert("Converted to lowercase!", "success"); } const handleClearClick = ()=>{ - let newText = ''; - setText(newText); + // let newText = ''; + // setText(newText); + setText("") props.showAlert("Text Cleared!", "success"); } @@ -32,8 +35,9 @@ export default function TextForm(props) { // Credits: Coding Wala const handleExtraSpaces = () => { - let newText = text.split(/[ ]+/); - setText(newText.join(" ")); + // let newText = text.split(/[ ]+/); + // setText(newText.join(" ")); + setText(text.replace(/\s+/g, ' ').trim()) props.showAlert("Extra spaces removed!", "success"); }