Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 구글맵스
- Kotlin
- JS
- JavaScript
- TypeScript
- 코틀린
- array
- Javscript
- TextView
- 랜덤번호
- Java
- 스프링부트
- GoogleMaps
- React
- Android
- Linux
- 자바스크립트
- SpringBoot
- RecyclerView
- scrollview
- 안드로이드
- npm
- 리액트
- fragment
- 오버라이딩
- Hook
- 랜덤넘버
- stylesheet
- button
- nodejs
Archives
- Today
- Total
타닥타닥 개발자의 일상
react 텍스트 입력하고 button 누르면 console창에 출력되게 하는 화면 만들기 (typescript/TextUnput/Button) 본문
코딩 기록/react
react 텍스트 입력하고 button 누르면 console창에 출력되게 하는 화면 만들기 (typescript/TextUnput/Button)
NomadHaven 2022. 3. 7. 16:51
App.tsx
import React, { useState } from "react";
import { Button, Text, TextInput, View } from "react-native";
let glTag:String
//사용되지 않는 함수
function MyFunc(props:any){
console.log(props.name)
props.setText('Money')
return <Text>{props.name}</Text>
}
export default function App(){
const [ inputTextValue, setInputTextValue ] =useState("")
const [text,setText] = useState("")
//setInputTextValue에 text값을 입력하는 함수
const handleChange = (event:any)=>{
const {eventCount, target, text} = event.nativeEvent //기본이벤트
setInputTextValue(text)
}
//버튼 누를때 호출되는 함수
function handleClick(){
console.log(inputTextValue)
console.log(text)
}
return(
<View>
<Text>I Love {text}</Text>
<TextInput value={inputTextValue} onChange={handleChange} placeholder="onChange"/>
<TextInput onChangeText={text=>setText(text)} placeholder="onChangeText"/>
<Button title="button" onPress={handleClick}/>
</View>
)
}
실행화면
TextInput 란에 Cat과 Dog을 입력한후 Button을 누르면
콘솔창에는 아래와 같이 출력된다.
'코딩 기록 > react' 카테고리의 다른 글
Comments