일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |
- 부의감각
- #FIFAONLINE4
- 바이트디그리
- 피온4
- 랜덤스쿼드
- 강아지 스마트 펜스
- 혼술 술자리 인싸앱
- fifaonline
- 랜덤
- 안드로이드#앱만들기#알바
- 안드로이드
- 독서감상문
- 내일배움카드
- K디지털크레딧
- 홈CCTV
- 패스트캠퍼스
- Ai
- fifaonline4
- 안드로이드 그림판#그림메모장#낙서장
- 자바 인강
- D-ID
- 안드로이드 #앱개발#계산기
- 아두이노#작품#사료급식기
- 불끌때
- 강아지 #박스집 #복층
- 안녕 디지몬
- 부르지마세요
- 박스#강아지집#만들기
- 스쿼드 메이커
- Java & SpringBoot로 시작하는 웹 프로그래밍
- Today
- Total
LC Studio
React Native 개념잡기 Learn the Basics #4 본문
Learn the Basics #3에 이어서...
State
Unlike props that are read-only and should not be modified, the state allows React components to change their output over time in response to user actions, network responses and anything else.
읽기 전용이므로 수정해서는 안 되는 props와 달리 state는 Responent 구성 요소가 사용자 작업, 네트워크 응답 등에 대응하여 시간이 지남에 따라 출력을 변경할 수 있도록 허용합니다.
What's the difference between state and props in React?
React에서의 state와 props의 차이점은??
In a React component, the props are the variables that we pass from a parent component to a child component. Similarly, the state are also variables, with the difference that they are not passed as parameters, but rather that the component initializes and manages them internally.
리액트 컴포넌트에서 props은 상위 컴포넌트에서 하위 컴포넌트로 전달되는 변수입니다. 마찬가지로 state도 변수이며 매개 변수로 전달되지 않고 구성 요소가 내부적으로 초기화하고 관리한다는 차이점이 있습니다.
ex)
// ReactJS Counter Example using Hooks!
import React, { useState } from 'react';
const App = () => {
const [count, setCount] = useState(0);
return (
<div className="container">
<p>You clicked {count} times</p>
<button
onClick={() => setCount(count + 1)}>
Click me!
</button>
</div>
);
};
// CSS
.container {
display: flex;
justify-content: center;
align-items: center;
}
// React Native Counter Example using Hooks!
import React, { useState } from 'react';
import { View, Text, Button, StyleSheet } from 'react-native';
const App = () => {
const [count, setCount] = useState(0);
return (
<View style={styles.container}>
<Text>You clicked {count} times</Text>
<Button
onPress={() => setCount(count + 1)}
title="Click me!"
/>
</View>
);
};
// React Native Styles
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
}
});
As shown above, there is no difference in handling the state between React and React Native. You can use the state of your components both in classes and in functional components using hooks!
위와 같이 React와 React Native의 상태 처리에는 차이가 없습니다. 후크를 사용하여 클래스 및 기능 구성요소에서 구성요소의 상태를 모두 사용할 수 있습니다!
'React Natice' 카테고리의 다른 글
React Native 개념잡기 Learn the Basics #2 (0) | 2022.02.01 |
---|---|
React Native 개념잡기 Learn the Basics #1 (0) | 2022.01.31 |