Skip to content

Commit b9ca23f

Browse files
Video 7 Completed
1 parent a45f91f commit b9ca23f

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/App.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import './App.css';
22
import Navbar from './components/Navbar';
3+
import TextForm from './components/TextForm';
34

45
function App() {
56
return (
67
<>
78
{/* <Navbar title="TextUtils" aboutText="About TextUtils" /> */}
89
{/* <Navbar/> */}
910
<Navbar title="TextUtils" />
11+
<div className="container my-3">
12+
<TextForm heading="Enter the text to analyze below"/>
13+
</div>
1014
</>
1115
);
1216
}

src/components/TextForm.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React, {useState} from 'react'
2+
3+
4+
export default function TextForm(props) {
5+
const handleUpClick = ()=>{
6+
// console.log("Uppercase was clicked: " + text);
7+
let newText = text.toUpperCase();
8+
setText(newText)
9+
}
10+
11+
const handleOnChange = (event)=>{
12+
// console.log("On change");
13+
setText(event.target.value)
14+
}
15+
16+
const [text, setText] = useState('Enter text here2');
17+
// text = "new text"; // Wrong way to change the state
18+
// setText("new text"); // Correct way to change the state
19+
return (
20+
<div>
21+
<h1>{props.heading}</h1>
22+
<div className="mb-3">
23+
<textarea className="form-control" value={text} onChange={handleOnChange} id="myBox" rows="8"></textarea>
24+
</div>
25+
<button className="btn btn-primary" onClick={handleUpClick}>Convert to Uppercase</button>
26+
</div>
27+
)
28+
}

0 commit comments

Comments
 (0)