Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 22103e0

Browse files
written first hook.
1 parent 54b9917 commit 22103e0

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

‎react-hooks/src/App.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React,{useState} from 'react';
22
import { Input } from 'antd';
33
import 'antd/es/input/style/index.css';
44
import './App.css';
@@ -8,13 +8,23 @@ import './App.css';
88
* In short, you can now use state, and other React features, within your functional React components.
99
* So, you don’t need a class to use state!
1010
* The biggest part to learn about hooks is the new way of declaring state. So as the first part of this app, let’s set up a component with state, the hooks way.
11+
12+
ref. https://medium.com/@dtkatz/react-hooks-tutorial-learn-by-building-b90ec4db2b8e
13+
14+
1115
*/
1216

1317
const App = () => {
18+
const [userText, setUserText] = useState('');
19+
const updateUserText = event => {
20+
setUserText(event.target.value);
21+
console.log(`current userText, ${userText}`);
22+
}
23+
1424
return (
1525
<div className="container">
1626
<h2>Type something...</h2>
17-
<Input placeholder="Basic usage"/>
27+
<Input placeholder="Basic usage"onChange={(e)=>updateUserText(e)}/>
1828
</div>
1929
)
2030
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /