React-Native Props

Ritslurrrr·2023년 12월 21일
0

React-Native

목록 보기
1/2

Props 기본값 설정

Case 1.

const App = ({props,height}) => {
	return(    
    	<View style={[props,{height:height}]}></View>
    )
}

App.defaultProps = {
	props: true
    height: 64
}

export default function App;

Case 2.

const App = ({props = true, height = 60}) => {
	return(
    	<View style={[props,{height:height}]}></View>
    )
}

export default function App;

Element에 Spread연산자 사용하기

Case 1.

Component.tsx

const Component = ({...rest}) => {
	return(
    	<TextInput {...rest}}></TextInput>
    )
}

export default function Component;

App.tsx

import Component from '../Component

const App = ({props = true, height = 60}) => {
	return(
    	<Component autoFocus ></Component>
    )
}

export default function App;

위처럼 Spread연산자를 사용하면 App에서 TextInput에 관한 props 작성시 적용된다.

profile
FullStackDeveloper(WEB,APP)

0개의 댓글