MapleStory Finger Point

๐Ÿ”ต React

[React] ์ปดํฌ๋„ŒํŠธ ๋ฐ˜๋ณต Iteration

HYEJU01 2024. 8. 28. 20:27

1. ์ปดํฌ๋„ŒํŠธ ๋ฐ˜๋ณต Iteration

 

 
๐Ÿ˜บ  ๋ฆฌ์•กํŠธ์—์„œ์˜ ๋ฐ˜๋ณต Iteration ์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์ž !!
 
 

๐Ÿ“ ๋ฆฌ์•กํŠธ์—์„œ์˜ ๋ฐ˜๋ณต

  1. ๋ชฉ๋ก ์š”์†Œ๋“ค์„ ๋ฐ˜๋ณต์ฒ˜๋ฆฌ ํ• ๋•Œ๋Š” mapํ•จ์ˆ˜๋ฅผ ์ด์šฉ ํ•ฉ๋‹ˆ๋‹ค.
  2. ๋ฐ˜๋ณต ์ปดํฌ๋„ŒํŠธ์—๋Š” ๋ฐ˜๋“œ์‹œ key props๋ฅผ ์ „๋‹ฌํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

 

 

 

 

๐Ÿ˜บ  ๋ฐฐ์—ด๊ณผ ๊ด€๋ จ๋œ map๊ณผ filter ๋ฉ”์„œ๋“œ์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด์ž.

 

๐Ÿ“  map ํ•จ์ˆ˜๋Š” ์‹คํ–‰ํ•œ ๊ฒฐ๊ณผ๋ฅผ ๊ฐ€์ง€๊ณ , ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์„ ๋งŒ๋“ค ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค.

array.map(callbackFunction(currenValue, index, array), thisArg)

  • currenValue: ํ˜„์žฌ๊ฐ’
  • index: ํ˜„์žฌ์ธ๋ฑ์Šค
  • array: ํ˜„์žฌ๋ฐฐ์—ด,
  • thisArg: callbackFunction ๋‚ด์—์„œ this๋กœ ์‚ฌ์šฉ๋  ๊ฐ’
const IterationComponent = () => {

    const arr = [1,2,3,4,5];
    const newArr = arr.map( item => item*10 )// => ํ•œ์ค„์ผ ๊ฒฝ์šฐ ๋ฆฌํ„ด
		console.log('map์œผ๋กœ ์ƒ๋กญ๊ฒŒ ๋งŒ๋“ค์–ด์ง„ newArr', newArr)

    return (
    	....
    )
}

 

 

 

๐Ÿ“  filter - ์š”์†Œ ๊ฐœ์ˆ˜๋งŒํผ ๋ฐ˜๋ณตํ•˜๋ฉฐ boolean์œผ๋กœ ๋ฆฌํ„ด๋œ ๊ฒฐ๊ณผ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ƒˆ๋กœ์šด list๋ฅผ ๋งŒ๋“ฌ

(๋ฐฐ์—ด์˜ ํŠน์ • ์กฐ๊ฑด์— ๋งž๋Š” ์š”์†Œ๋“ค๋งŒ ์ถ”์ถœํ•˜์—ฌ ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์„ ๋งŒ๋“ค ๋•Œ ์‚ฌ์šฉ)

array.filter(callbackFunction(currenValue, index, array), thisArg)

  • currenValue: ํ˜„์žฌ๊ฐ’
  • index: ํ˜„์žฌ์ธ๋ฑ์Šค
  • arrayt: ํ˜„์žฌ๋ฐฐ์—ด
  • thisArg: callbackFunction ๋‚ด์—์„œ this๋กœ ์‚ฌ์šฉ๋  ๊ฐ’

 

 


 

๐Ÿ˜บ  map ์˜ ์ฝœ๋ฐฑํ•จ์ˆ˜์— ๋ฆฌํ„ด๊ฐ’์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์žˆ๋Š”๋ฐ, ๋‹ค์–‘ํ•œ ์žฅ์ ์ด ์žˆ๋‹ค. !!

๋ฆฌํ„ด ๊ฐ’์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ณด๋„๋กํ•˜์ž!

 

 

๐Ÿ“ map ์ฝœ๋ฐฑํ•จ์ˆ˜์˜ ๋ฆฌํ„ด

  1. map์˜ ์ฝœ๋ฐฑํ•จ์ˆ˜์˜ ๋ฆฌํ„ด์— ๋ฐ˜๋ณต์‹œํ‚ฌ ํƒœ๊ทธ๋ฅผ ๋„ฃ์Šต๋‹ˆ๋‹ค.
  2. ๋ฆฌ์•กํŠธ์—์„œ key๋Š” ๋ฐฐ์—ด์„ ๋ Œ๋”๋ง ์‹œํ‚ฌ๋•Œ ๋น ๋ฅด๊ฒŒ ๋ณ€ํ™”๋ฅผ ๊ฐ์ง€ํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•˜๋Š” ์†์„ฑ์ž…๋‹ˆ๋‹ค.
  3. key๋Š” index๋Œ€์‹  ๊ณ ์œ ํ•œ ๊ฐ’์„ ๋„ฃ์–ด ์ฃผ๋„๋ก ๊ถŒ์œ  ๋ฉ๋‹ˆ๋‹ค. (key๋ฅผ ๋„ฃ์ง€ ์•Š์œผ๋ฉด props์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒ ๋ฉ๋‹ˆ๋‹ค.)
const IterationComponent = () => {

    const arr = [1,2,3,4,5];
    const newArr = arr.map((item, index) => {
	    return <li key={๊ณ ์œ ํ•œ์‹๋ณ„๊ฐ’}>{item}</li> 
    })

    return (
        <ul>
            {newArr}
        </ul>
    )
}

export default IterationComponent;

 

 

 

 

 

 

๐Ÿ˜บ  ๋ฐฐ์—ด์„ ํ•ฉ์น˜๋Š” ๋ฐฉ๋ฒ•๋„ ์•Œ์•„์•ผ๊ฒ ์ง€ !

 

๐Ÿ“ concat ๋ฉ”์„œ๋“œ

const array1 = ['a', 'b', 'c'];
const array2 = ['d', 'e', 'f'];
const array3 = array1.concat(array2);

console.log(array3); //["a", "b", "c", "d", "e", "f"]

 

 

๐Ÿ“ ์ „๊ฐœ๊ตฌ๋ฌธ  - ์ „๊ฐœ ์—ฐ์‚ฐ์ž (...)

const array1 = ['a', 'b', 'c'];
const array2 = ['d', 'e', 'f'];

const array3 = [...array1, ...array2];
console.log(array3); //["a", "b", "c", "d", "e", "f"]

 

 

๐Ÿ“  push ๋ฉ”์„œ๋“œ์™€ ์ „๊ฐœ ์—ฐ์‚ฐ์ž

const arr1 = [1, 2, 3];
const arr2 = [4, 5, 6];

arr1.push(...arr2);
console.log(arr1); // [1, 2, 3, 4, 5, 6]

 

 

์ด์™ธ์—๋„ ํ•ฉ์น˜๋Š” ๋ฐฉ๋ฒ•์€ ๋‹ค์–‘ํ•˜๋‹ค!

 

 


 

 

 

[App.js]

 

import { Fragment } from "react";
import IterationComponent from "./component/IterationComponent";
import IterationComponent3 from "./component/IterationComponent3";
import IterationComponent4 from "./component/IterationComponent4";
import IterationComponentQ2 from "./component/IterationComponentQ2";


function App() {
  return (

    <Fragment>
      <IterationComponent />
      <IterationComponent3 />
      <IterationComponent4 />
      <IterationComponentQ2 />
    </Fragment>
  )

}

export default App;

 

 

[IterationComponent.js]

function IterationComponent() {

  const arr = [1,2,3,4,5];

  // const newArr = arr.map((value, index) => {
  //   return value * 10;
  // })

  //const newArr = arr.map((value, index) => value * 10);

  // li ํƒœ๊ทธ ๋ฆฌ์•กํŠธ elemet ๋ฐ˜๋“œ์‹œ ๊ณ ์œ ํ•œ key props ์ „๋‹ฌํ•˜๋„๋ก ํ•ด์•ผํ•จ
  const newArr = arr.map((value,index) => { 
    return <li style={{listStyle:'none'}} key={index}> ๊ฐ’ : {value} </li>
  } )



  console.log(newArr);

  return (
    <div>
        <ul>
          {newArr}
        </ul>
    </div>
  ) 
}

export default IterationComponent;

 

 

 

const arr = [1,2,3,4,5];

const newArr = arr.map((value, index) => {
    return value * 10;
})

const newArr = arr.map((value, index) => value * 10);

 

 

 


  const newArr = arr.map((value,index) => { 
    return <li style={{listStyle:'none'}} key={index}> ๊ฐ’ : {value} </li>
  } )

 

  • ๋ฆฌ์•กํŠธ element ๋ฐ˜๋“œ์‹œ ๊ณ ์œ ํ•œ key props ์ „๋‹ฌํ•˜๋„๋ก ํ•ด์•ผํ•œ๋‹ค.

 


 

[IterationComponent2.js]

import { useState } from "react";

function IterationComponent3() {

  const data = [
    {id:1, topic:"hi"},
    {id:2, topic:"zz"},
  ];

  let [list, setList] = useState(data);

  //input ํƒœ๊ทธ state ๋กœ ๊ด€๋ฆฌ
  let [topic, setTopic] = useState('');

  
  // ๋ฒ„ํŠผ ํด๋ฆญ์‹œ์— input state ๊ฐ’์„ ๋ฐฐ์—ด์—๋‹ค๊ฐ€ ์ถ”๊ฐ€ํ•˜๊ธฐ
  
  let handleClick = () => {
    let obj = {id : list[list.length-1].id + 1, topic : topic };
    let newList = list.concat(obj);
    //console.log(newList);
    setList(newList); // ๋‹ค์‹œ ๊ทธ๋ฆฌ๊ฒŒ๋จ state ์—…๋ฐ์ดํŠธ ๋ฆฌ๋ Œ๋”๋ง
    setTopic('');
  }
  
  
  //๋”๋ธ”ํด๋ฆญ ์ด๋ฒคํŠธ
  
  let handleRemove = (id) => {

    // filter  ํ•ด๋‹น๊ฐ’์ด 
    let newList = list.filter((value) => {
      return value.id !== id; //  ๋ฆฌํ„ด์— ์‹ค๋ฆฐ ๊ฐ’์ด true ์ธ ๋ฐ์ดํ„ฐ๋งŒ ํ•„ํ„ฐ๋ง
    } )
    
    setList(newList);
  }
  
    // ๋ฆฌ์ŠคํŠธ๋กœ ๋ฐ˜๋ณต ์ฒ˜๋ฆฌ - ์ด๋ฒคํŠธ๊ฐ€ ํƒœ๊ทธ๋ณด๋‹ค ์œ„์ชฝ์— ์œ„์น˜ํ•ด์•ผํ•จ
    // ์ด๋ฒคํŠธํ•จ์ˆ˜์— ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์ฃผ๊ณ  ์‹ถ์œผ๋ฉด () => {์‹คํ–‰์‹œํ‚ฌํ•จ์ˆ˜(๋งค๊ฐœ๊ฐ’)}
    const newList = list.map( value => <li style={{color:'blue'}} 
                                            key={value.id} 
                                            onDoubleClick={()=>{handleRemove(value.id)}}>  {value.topic} </li>)
  return (
    <div>
      
      <h3> ๊ฐ„๋‹จํ•œ ํ• ์ผ ๋ชฉ๋ก ๋งŒ๋“ค๊ธฐ </h3>

      <ul>
        {newList}
      </ul>

      <input type="text" value={topic} onChange={(e)=> setTopic(e.target.value)}/>
      <button type="button" onClick={handleClick}> ์ถ”๊ฐ€ํ•˜๊ธฐ </button>

    </div>

  ) 
}

export default IterationComponent3;

 

 

  const data = [
    {id:1, topic:"hi"},
    {id:2, topic:"zz"},
  ];

  let [list, setList] = useState(data);

  //input ํƒœ๊ทธ state ๋กœ ๊ด€๋ฆฌ
  let [topic, setTopic] = useState('');

 

 

 

 // ๋ฒ„ํŠผ ํด๋ฆญ์‹œ์— input state ๊ฐ’์„ ๋ฐฐ์—ด์—๋‹ค๊ฐ€ ์ถ”๊ฐ€ํ•˜๊ธฐ
  
  let handleClick = () => {
    let obj = {id : list[list.length-1].id + 1, topic : topic };
    let newList = list.concat(obj);
    //console.log(newList);
    setList(newList); // ๋‹ค์‹œ ๊ทธ๋ฆฌ๊ฒŒ๋จ state ์—…๋ฐ์ดํŠธ ๋ฆฌ๋ Œ๋”๋ง
    setTopic('');
  }

 

  • ํด๋ฆญ์‹œ ๋ฐฐ์—ด์— ๊ฐ’ ์ถ”๊ฐ€

 

 

//๋”๋ธ”ํด๋ฆญ ์ด๋ฒคํŠธ
  let handleRemove = (id) => {

    // filter  ํ•ด๋‹น๊ฐ’์ด 
    let newList = list.filter((value) => {
      return value.id !== id; //  ๋ฆฌํ„ด์— ์‹ค๋ฆฐ ๊ฐ’์ด true ์ธ ๋ฐ์ดํ„ฐ๋งŒ ํ•„ํ„ฐ๋ง
    } )
    
    setList(newList);
  }

 

  •  ๋”๋ธ”ํด๋ฆญ ์ด๋ฒคํŠธ 

 

// ๋ฆฌ์ŠคํŠธ๋กœ ๋ฐ˜๋ณต ์ฒ˜๋ฆฌ - ์ด๋ฒคํŠธ๊ฐ€ ํƒœ๊ทธ๋ณด๋‹ค ์œ„์ชฝ์— ์œ„์น˜ํ•ด์•ผํ•จ
    // ์ด๋ฒคํŠธํ•จ์ˆ˜์— ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์ฃผ๊ณ  ์‹ถ์œผ๋ฉด () => {์‹คํ–‰์‹œํ‚ฌํ•จ์ˆ˜(๋งค๊ฐœ๊ฐ’)}
    const newList = list.map( value => <li style={{color:'blue'}} 
                                            key={value.id} 
                                            onDoubleClick={()=>{handleRemove(value.id)}}>  {value.topic} </li>)

 

 

 

 <ul>
     {newList}
 </ul>

 

 

      <input type="text" value={topic} onChange={(e)=> setTopic(e.target.value)}/>
      <button type="button" onClick={handleClick}> ์ถ”๊ฐ€ํ•˜๊ธฐ </button>

 

 

 



 


[IterationComponent3.js]

import { useState } from "react";
//import img1 from '../img/img1.png';


/*
์ด๋ฏธ์ง€๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ๋ฐฉ๋ฒ•
1. ์™ธ๋ถ€ ์„œ๋ฒ„์—์„œ ๊ฒฝ๋กœ ์ฐธ์กฐ ๋ฐ›๊ธฐ (๊ฐ€์žฅ ์ผ๋ฐ˜์ ์ธ ๋ฐฉ๋ฒ•)

2. src๋ฐ‘์œผ๋กœ ๋„ฃ๋Š”๊ฒฝ์šฐ (img1 ์œผ๋กœ ํ•˜๋‚˜์˜ ์ด๋ฏธ์ง€ ์ฐธ์กฐ๊ฐ€๋Šฅ)
import img1 from '../img/1.jpg'; 

3. public๋ฐ‘์œผ๋กœ ๋„ฃ๋Š”๊ฒฝ์šฐ๋Š” ๋ฐ”๋กœ ์ฐธ์กฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
*/

const IterationComponent4 = () => {

    //๋ฐ์ดํ„ฐ - publicํด๋”๋ฐ‘์— ์˜ˆ์‹œ๋กœ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ๋„ฃ์Šต๋‹ˆ๋‹ค.
    const arr = [
        {src : '/img/img1.png', title : '์•„์ดํฐ10', price: 1000},
        {src : '/img/img2.png', title : '์•„์ดํฐ11', price: 2000},
        {src : '/img/img3.png', title : '์•„์ดํฐ12', price: 3000},
        {src : '/img/img4.png', title : '์•„์ดํฐ13', price: 4000},
    ]
  
    let [img, setImg] = useState('');
    //๋ถ€๋ชจ์—๊ฒŒ ๊ฑธ๋ฉด ์ž์‹๋„ ๊ฑธ๋ฆฌ๋Š” ํŠน์„ฑ์„ ์ด์šฉํ•ด๋„ ๋œ๋‹ค.
    //const [im,setIm] = useState('"/img/img1.png"')

    let handleClick = (e) => {
      console.log(e.target);
      console.log(e.target.src);
      // let obj = {id : list[list.length-1].id + 1, topic : topic };
      // let newList = list.concat(obj);
      // //console.log(newList);
      // setList(newList); // ๋‹ค์‹œ ๊ทธ๋ฆฌ๊ฒŒ๋จ state ์—…๋ฐ์ดํŠธ ๋ฆฌ๋ Œ๋”๋ง
      // setTopic('');
      setImg(e.target.src);
      // if (e.target.tagName != "IMG") return;
      // let img = e.target.src ;
      // setImg(img);
    }




    // ๋ชฉ๋ก ์ถœ๋ ฅ  IMG ๋Š” ๊ฐ ํ•˜๋‚˜์˜ ๊ฐ์ฒด๊ฐ€ ๋œ๋‹ค !! 
    const newArr = arr.map((img, index) => {
      return <div key={index} >  <img src={img.src} onClick={handleClick} /> <p style={{color:'blue'}}> ์ƒํ’ˆ : {img.title} </p> <p> ๊ฐ€๊ฒฉ :{img.price}</p> </div> 
    } )

    return (
        <div>
            <hr/>
            <h3>์ด๋ฏธ์ง€ ๋ฐ์ดํ„ฐ ๋ฐ˜๋ณตํ•ด๋ณด๊ธฐ</h3>
            {/* <img src="https://raw.githubusercontent.com/yopy0817/data_example/master/img/img1.png" alt="๋ด„" width="100" /> */}
            {/*   <img src={img1}> */}
            {/* <img src="/img/img1.png" /> */}
            <img src={img} width={'300px'}/>

            {/* 
            <div>
                <div>
                    <img src="/img/img1.png" width="100" />
                    <p>
                        ์ œ๋ชฉ
                    </p>
                    <p>
                        ๊ฐ€๊ฒฉ
                    </p>
                </div> 
            <div>
            */}

            {/* 3๋ฒˆ */}


            <div style={{display:'flex', textAlign:'center', fontWeight:'600'}}> 
               {newArr}
            </div>

        </div>
    )

}

export default IterationComponent4;

 

 

 

 

 

 

    //๋ฐ์ดํ„ฐ - publicํด๋”๋ฐ‘์— ์˜ˆ์‹œ๋กœ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ๋„ฃ์Šต๋‹ˆ๋‹ค.
    const arr = [
        {src : '/img/img1.png', title : '์•„์ดํฐ10', price: 1000},
        {src : '/img/img2.png', title : '์•„์ดํฐ11', price: 2000},
        {src : '/img/img3.png', title : '์•„์ดํฐ12', price: 3000},
        {src : '/img/img4.png', title : '์•„์ดํฐ13', price: 4000},
    ]

 

 

 

    let [img, setImg] = useState('');
    //๋ถ€๋ชจ์—๊ฒŒ ๊ฑธ๋ฉด ์ž์‹๋„ ๊ฑธ๋ฆฌ๋Š” ํŠน์„ฑ์„ ์ด์šฉํ•ด๋„ ๋œ๋‹ค.
    //const [im,setIm] = useState('"/img/img1.png"')

 

 

    let handleClick = (e) => {
      console.log(e.target);
      console.log(e.target.src);
      // let obj = {id : list[list.length-1].id + 1, topic : topic };
      // let newList = list.concat(obj);
      // //console.log(newList);
      // setList(newList); // ๋‹ค์‹œ ๊ทธ๋ฆฌ๊ฒŒ๋จ state ์—…๋ฐ์ดํŠธ ๋ฆฌ๋ Œ๋”๋ง
      // setTopic('');
      setImg(e.target.src);
      // if (e.target.tagName != "IMG") return;
      // let img = e.target.src ;
      // setImg(img);
    }
  • ํด๋ฆญ ์ด๋ฒคํŠธ : ์ด๋ฏธ์ง€ ํด๋ฆญ์‹œ ๋ฉ”์ธ ์ด๋ฏธ์ง€ ๋ณ€๊ฒฝ๋จ

 

 

 

    // ๋ชฉ๋ก ์ถœ๋ ฅ  IMG ๋Š” ๊ฐ ํ•˜๋‚˜์˜ ๊ฐ์ฒด๊ฐ€ ๋œ๋‹ค !! 
    const newArr = arr.map((img, index) => {
      return <div key={index} >  <img src={img.src} onClick={handleClick} /> <p style={{color:'blue'}}> ์ƒํ’ˆ : {img.title} </p> <p> ๊ฐ€๊ฒฉ :{img.price}</p> </div> 
    } )

 

 

 

 

 

<img src="https://raw.githubusercontent.com/yopy0817/data_example/master/img/img1.png" alt="๋ด„" width="100" />
<img src={img1}>
<img src="/img/img1.png" />

 

  • ์ด๋ฏธ์ง€ ๋„์šฐ๊ธฐ 

 

 

        <div>
            <hr/>
            <h3>์ด๋ฏธ์ง€ ๋ฐ์ดํ„ฐ ๋ฐ˜๋ณตํ•ด๋ณด๊ธฐ</h3>

            <img src={img} width={'300px'}/>

            <div style={{display:'flex', textAlign:'center', fontWeight:'600'}}> 
               {newArr}
            </div>

        </div>

 

 

 

 

 


 

 

[IterationComponentQ2.js]

 

import { useState } from "react";

const IterationComponentQ2 = () => {
    //1 - select๋Š” ์ปดํฌ๋„ŒํŠธ๋ฐ˜๋ณต์œผ๋กœ optionํƒœ๊ทธ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
    const select = ['HTML', 'Javascript', 'CSS', 'Java', 'Oracle', 'Mysql'];

    //2 - ์•„๋ž˜ ๋ฐ์ดํ„ฐ๋Š” state๋กœ ๊ด€๋ฆฌํ•˜๊ณ  ํ™”๋ฉด์— liํƒœ๊ทธ๋กœ ๋ฐ˜๋ณตํ•ด์ฃผ์„ธ์š” .
    const data = [
        {id: 1, type: 'Java', teacher: '์ด์ˆœ์‹ '},
        {id: 2, type: 'Java', teacher: 'ํ™๊ธธ์ž'},
        {id: 3, type: 'Javascript', teacher: 'ํ™๊ธธ๋™'},
        {id: 4, type: 'Oracle', teacher: '์ด์ˆœ์‹ '},
        {id: 5, type: 'Mysql', teacher: '์ด์ˆœ์‹ '},
        {id: 6, type: 'CSS', teacher: '๋ฐ•์ฐฌํ˜ธ'},
        {id: 7, type: 'HTML', teacher: 'coding404'},
    ];
    const [list, setList] = useState(data);

    //3 - ์…€๋ ‰ํŠธ๋ฐ•์Šค๊ฐ€ ์ฒด์ธ์ง€๋˜๋ฉด ์ด๋ฒคํŠธ๊ฐ์ฒด๋ฅผ ํ™œ์šฉํ•ด์„œ ์„ ํƒ๋œ ๊ฐ’๋งŒ ํ•„ํ„ฐ๋งํ•ด์ฃผ์„ธ์š”.
    let handleChange = (e) => {
        //data์—์„œ ํ•„ํ„ฐ๋ง
        let newList = data.filter( item => item.type === e.target.value );
        setList(newList);
    }
	//4- input๊ฐ’์€ state๋กœ ๊ด€๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
    //5 - ๊ฒ€์ƒ‰๊ธฐ๋Šฅ - ์›๋ณธ data์—์„œ ํ•„ํ„ฐ๋ง์œผ๋กœ ๊ฒ€์ƒ‰๊ฐ’์„ ์ฐพ์•„ state๋ฅผ ์—…๋ฐ์ดํŠธ ํ•ฉ๋‹ˆ๋‹ค.
    const [input, setInput] = useState('');
    const handleClick = () => {

        let newList = data.filter( item => {
            let str = item.type.concat(item.teacher).toLowerCase(); //๋ฌธ์ž์—ด ๋ถ™์ด๊ธฐ
            return str.includes(input); //ํฌํ•จ๋˜์–ด ์žˆ์œผ๋ฉด true
        });
        setList(newList); //state๋ณ€๊ฒฝ
    }

    return (
        <div>java
			<hr/>
            <h3>์‹ค์Šต</h3>
            Search: <input type="text" value={input} onChange={ (e) => setInput(e.target.value) }/>
            <button onClick={handleClick} >๊ฒ€์ƒ‰</button>

            <br/>
            
			๊ณผ๋ชฉ์ฐพ๊ธฐ:
            <select onChange={handleChange}>
                {
                    select.map( (item, index) => <option key={index}>{item}</option>)
                }
            </select>
            <ul>
                {
                    list.map( item => <li key={item.id}>{item.type}-{item.teacher}</li>)
                }
            </ul>
        </div>
    )
}

export default IterationComponentQ2;