Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions hooks/src/App.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import React from 'react'
import './App.css';
import ClassCounter from "./components/ClassCounter";
import HookCounter from "./components/HookCounter";
// import HookCounter from "./components/HookCounter";
import HookCounterThree from "./components/HookCounterThree";
import HookCounterFour from "./components/HookCounterFour";

function App() {
return (
<div className="App">
{/*<ClassCounter/>*/}
<HookCounter/>
{/*<HookCounter/>*/}
{/*<HookCounterThree/>*/}
<HookCounterFour/>
</div>
);
}
Expand Down
26 changes: 26 additions & 0 deletions hooks/src/components/HookCounterFour.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React, { useState } from 'react'

function HookCounterFour() {
const [name,setName]= useState({firstName: '', lastName: ''})

return (
<div>
<form>
<input
type="text"
value={name.firstName}
onChange={e => setName({...name,firstName: e.target.value})}/>
<input type="text"
value={name.lastName}
onChange={e => setName({...name,lastName: e.target.value})}/>
<h2>Your first name is - {name.firstName}</h2>
<h2>Your last name is - {name.lastName}</h2>
<h2>{JSON.stringify(name)}</h2>

</form>
</div>
)

}

export default HookCounterFour
23 changes: 23 additions & 0 deletions hooks/src/components/HookCounterThree.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React, { useState } from 'react'

function HookCounterThree() {
const initialCount =0
const [count, setCount] = useState(initialCount)

const incrementFive =() => {
for (let i=0; i<5; i++) {
setCount(prevCount => prevCount + 1 )
}
}
return(
<div>
Count: {count}
<button onClick={() => setCount(initialCount)}>Reset</button>
<button onClick={() => setCount(prevCount => prevCount + 1)}>Increment</button>
<button onClick={() => setCount(prevCount => prevCount - 1)}>Decrement</button>
<button onClick={incrementFive}>Increment 5</button>
</div>
)
}

export default HookCounterThree