반응형
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 | 29 | 30 |
Tags
- node
- IOS
- linux
- androidstudio
- 개발
- build
- TensorFlow
- 센토스
- VirtualBox
- 맥
- 네트워크
- localserver
- jest
- xcode
- MachineLearning
- Chrome
- vsCode
- centos
- Android
- avds
- MAC
- unittest
- 리눅스
- webpack
- picker
- react
- qunit
- ReactNative
- PYTHON
Archives
- Today
- Total
로메오의 블로그
[React Native] scrollview 본문
반응형
import React, {useState} from 'react';
import {View, Text, StyleSheet, Button, ScrollView} from 'react-native';
interface State {
name: string;
}
export default function App() {
const [companies, setCompany] = useState<State[]>([
{name: 'google'},
{name: 'samsung'},
{name: 'microsoft'},
{name: 'facebook'},
{name: 'apple'},
]);
const add = () => {
const newCompany = {name: 'newCompany'};
setCompany(prevArray => [...prevArray, newCompany]);
};
const remove = (name: string) => {
setCompany(prevArray => prevArray.filter(item => item.name !== name));
};
return (
<View style={styles.container}>
<Text style={styles.title}>Company</Text>
<ScrollView>
{companies.map((company, index) => {
return (
<View style={styles.text} key={index}>
<Text>{company.name}</Text>
<Button title="삭제" onPress={() => remove(company.name)} />
</View>
);
})}
<Button title="추가" onPress={add} />
</ScrollView>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
marginTop: 50,
},
title: {
fontSize: 20,
padding: 10,
},
text: {
backgroundColor: '#eee',
padding: 10,
margin: 10,
},
});
반응형
'Frontend > React' 카테고리의 다른 글
[React Native] custom font 설정 (0) | 2022.10.17 |
---|---|
[React Native] redux (0) | 2022.10.17 |
[React Native] useState (0) | 2022.10.13 |
[React Native] state (0) | 2022.10.13 |
[React Native] Tab navigation 사용하기 (2022년 기준) (0) | 2022.10.12 |
Comments