일기장 App.ts

import { Component, createElement } from 'react';

import { FlatList, Text, TouchableOpacity, View } from 'react-native';

 

type triple = { id: number, title: string, content: string };

type ItemProps = { element: any, on_press: () => void, colour: string };

 

class Item extends Component<ItemProps> {

  render() {

    return createElement(

      TouchableOpacity,

      { onPress: this.props.on_press, style: { backgroundColor: this.props.colour }},

      createElement(Text, {}, this.props.element.title)

    )

  }

}

 

export default class App extends Component<undefined, { index: number }> {

  private data: triple[] = [

    { id: 0, title: '가', content: 'A' },

    { id: 1, title: '나', content: 'B' },

    { id: 2, title: '다', content: 'C' },

    { id: 3, title: '라', content: 'D' }

  ];

 

  constructor(props: undefined) {

    super(props);

    this.state = { index: 0 };

  }

 

  render() {

    return createElement(

      View,

      {},

      createElement(

        FlatList,

        { 

          data: this.data,

          renderItem: ({ item }) => createElement(

            Item,

            { 

              element: item,

              on_press: () => this.setState({ index: item.id }),

              colour: item.id == this.state.index ? 'palegreen' : 'mediumspringgreen'

            }

          )

        }

      ),

      createElement(Text, {}, this.data[this.state.index].content)

    );

  }

}

댓글 7

luve 2022.06.08. 14:36
울집 옆방 드간 거 같네
댓글
리눅스 작성자 2022.06.08. 16:14
 천조국냥아치
왜 보기싫어?!
ㅠㅠ
댓글
리눅스 작성자 2022.06.08. 16:17
 천조국냥아치
고건 ㅆㅇㅈ이지
댓글
권한이 없습니다. 로그인

신고

"님의 댓글"

이 댓글을 신고 하시겠습니까?

삭제

"님의 댓글"

이 댓글을 삭제하시겠습니까?

분류 제목 글쓴이 날짜 조회 수
공지 [공지] 츄르내역_240102 19 조유리 3076 12
공지 [공지] 공지사항_220412 30 조유리 6539 64
일기장
이미지
Sso! 31 1
일기장
기본
메르시장인 51 7
일기장
기본
메르시장인 60 7
일기장
기본
메르시장인 82 14
일기장
기본
메르시장인 59 9
일기장
기본
메르시장인 55 5
일기장
기본
메르시장인 41 5
일기장
기본
메르시장인 44 8
일기장
기본
메르시장인 69 11
일기장
기본
메르시장인 64 8
일기장
기본
철이두개면두철 28 3
일기장
기본
메르시장인 46 8
일기장
이미지
♥무케♥ 35 3
일기장
이미지
구내염에는알보칠 158 5
일기장
기본
메르시장인 63 9
일기장
기본
메르시장인 58 8
일기장
이미지
정진솔 31 3
일기장
이미지
정진솔 64 7
일기장
기본
육상천재방예나 62 5
일기장
기본
메르시장인 80 10