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
- 스프링부트
- SpringBoot
- JS
- 코틀린
- Android
- 자바스크립트
- nodejs
- 구글맵스
- stylesheet
- 랜덤번호
- 안드로이드
- Hook
- Java
- button
- TypeScript
- Linux
- array
- fragment
- scrollview
- npm
- JavaScript
- TextView
- Javscript
- RecyclerView
- React
- GoogleMaps
Archives
- Today
- Total
타닥타닥 개발자의 일상
react / useEffect 써서 버튼 누를때 특정 텍스트 화면에 보이게 하기 / typescript 본문
실행문
npx react-native init sample20 --template react-native-template-typescript
App.tsx
import React, { useEffect, useState } from "react";
import { Button, Text, View } from "react-native";
/*
useEffect: 컴퍼넌트가 rendering 될때마다 특정 작업을 실행할 수 있도록 하는 hook
compoentDidMount + componentDidUpdate + componentWillUnmount
*/
function Welcome(props:any) {
console.log('start')
useEffect(()=>{ //==$(document).ready()
props.setText('My World')
console.log('useEffect')
})
console.log('end')
function func(){
props.setText('world')
}
return(
<View>
<Text>Welcome</Text>
<Button title="button" onPress={func}></Button>
</View>
)
}
export default function App(){
//get set
const [text,setText] =useState('abc')
return(
<View>
<Text>hello {text}</Text>
<Welcome setText={setText}/>
</View>
)
}
버튼 누르면 Hello My World 라는 텍스트가 보인가
Welcome 함수 안에 있는 uesEffect로 인해 text는 My World로 세팅되고 콘솔에 useEffect가 출력되었다.
'코딩 기록 > react' 카테고리의 다른 글
react UseMemo 사용하여 특정 함수만 호출되는 예제 보기 / typescript / useCallback함수 이용하여 버튼 클릭시 숫자 증가시키기 (0) | 2022.03.08 |
---|---|
react 현재시간 화면에 나타나고 초마다 갱신되게하기 / typescript 시계 만들기 (0) | 2022.03.08 |
react / flex 이용하여 원하는 비율로 화면에 아이템 구현하기 / typescript (0) | 2022.03.07 |
react / flex 속성 이용하여 화면 비율 조정하기 (typescript) (0) | 2022.03.07 |
react / 색상코드와 방향 조절로 화면에 색상카드 만들기 / SafeAreaView / transform : rotateX, rotateZ (0) | 2022.03.07 |
Comments