Skip to content

Commit 073d910

Browse files
Video 11 Completed
1 parent ad56a77 commit 073d910

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/components/TextForm.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,21 @@ export default function TextForm(props) {
2323
setText(event.target.value)
2424
}
2525

26+
// Credits: A
27+
const handleCopy = () => {
28+
console.log("I am copy");
29+
var text = document.getElementById("myBox");
30+
text.select();
31+
text.setSelectionRange(0, 9999);
32+
navigator.clipboard.writeText(text.value);
33+
}
34+
35+
// Credits: Coding Wala
36+
const handleExtraSpaces = () => {
37+
let newText = text.split(/[ ]+/);
38+
setText(newText.join(" "))
39+
}
40+
2641
const [text, setText] = useState('');
2742
// text = "new text"; // Wrong way to change the state
2843
// setText("new text"); // Correct way to change the state
@@ -36,6 +51,8 @@ export default function TextForm(props) {
3651
<button className="btn btn-primary mx-1" onClick={handleUpClick}>Convert to Uppercase</button>
3752
<button className="btn btn-primary mx-1" onClick={handleLoClick}>Convert to Lowercase</button>
3853
<button className="btn btn-primary mx-1" onClick={handleClearClick}>Clear Text</button>
54+
<button className="btn btn-primary mx-1" onClick={handleCopy}>Copy Text</button>
55+
<button className="btn btn-primary mx-1" onClick={handleExtraSpaces}>Remove Extra Spaces</button>
3956
</div>
4057
<div className="container my-3">
4158
<h2>Your text summary</h2>

0 commit comments

Comments
 (0)