로메오의 블로그

[React Native] state 본문

Frontend/React

[React Native] state

romeoh 2022. 10. 13. 16:00
반응형

React 목록

 

import React, {Component} from 'react';
import {View, Text, StyleSheet, Button} from 'react-native';

interface State {
  name: string;
  age: 0;
}

export default class App extends Component<State> {
  state: State = {
    name: '',
    age: 0,
  };

  render() {
    return (
      <View style={styles.container}>
        <Text>{this.state.name}</Text>
        <Button
          title="변경"
          onPress={() => {
            this.setState({
              name: 'hello',
            });
          }}
        />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    alignContent: 'center',
  },
});

 

 

React 목록

반응형
Comments