๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿฟ Project

[SidePJ] airdnd 3๋ถ€ - ํšŒ๊ณ ์™€ ๋งˆ๋ฌด๋ฆฌ

by Tamii 2021. 6. 6.
๋ฐ˜์‘ํ˜•

์ฃผ๋ง๋™์•ˆ ์ฝ”๋“œ๋ฆฌ๋ทฐ ๋ฐ›์€๊ฑธ ๊ณ ์น˜๋ฉฐ ์›”์š”์ผ ํ•œ์ฃผ ์‹œ์ž‘ !

 

๐Ÿ“Œ ์—ฐ์†ํด๋ฆญ ๋ฐฉ์ง€ํ•˜๊ธฐ 

ํ˜„์žฌ airdnd์˜ ๋‹ฌ๋ ฅ ํ™”์‚ดํ‘œ๋ฅผ ๋ˆ„๋ฅด๋ฉด ๋‹ค๋ฅธ ๋‹ฌ๋กœ ๋„˜์–ด๊ฐ€๋Š”๋ฐ, ์—ฌ๊ธฐ์„œ ์‚ฌ์šฉ์ž๊ฐ€ ์—ฐ์†์œผ๋กœ ํด๋ฆญ์„ ํ•˜๊ฒŒ ๋˜๋ฉด ์ด๋ฒคํŠธ๊ฐ€ ๊ผฌ์ผ ์ˆ˜ ์žˆ์–ด preventClick์ด๋ผ๋Š” ํ•จ์ˆ˜๋กœ ๋ฐฉ์ง€๋ฅผ ํ•ด๋†“์•˜๋‹ค.

 

 

๋ณ€๊ฒฝ ์ „

 const preventClick = () => {
    setTimeout(() => {
      setDisabled(false);
    }, 200);
    
 
const handleClick = () => {
    if (disabled) return;
    setDisabled(true);
    
    preventClick();

ํด๋ฆญ์„ ๋ˆ„๋ฅด๋ฉด disabled๋ฅผ true๋กœ ๋ฐ”๊ฟ” preventClick์ด ๋‹ค ๋™์ž‘ํ•˜๋Š” 2์ดˆ๋™์•ˆ ํด๋ฆญ์ด ๋ถˆ๊ฐ€ํ–ˆ๋‹ค๊ฐ€ 

2์ดˆ ํ›„์—๋Š” disabled = false๋กœ ๋ฐ”๊ฟ” ํด๋ฆญ์ด ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•˜๋Š” ๋ฐฉ์‹์ด์—ˆ๋‹ค.

๋ฐฐ์› ์—ˆ์ง€๋งŒ ์ž ์‹œ ์žŠ์—ˆ๋˜ ๋น„๋™๊ธฐ ์ œ์–ด = ์‹œ๊ฐ„ ๊ธฐ๋ฐ˜์˜ ๋ณ€๊ฒฝ์€ ์‹œ๊ฐ„์— ๊ด€๋ จ๋ ๋•Œ๋งŒ ์‚ฌ์šฉํ•˜๊ณ  ๊ทธ ์™ธ์—๋Š” ์‚ฌ์ด๋“œ ์ดํŽ™ํŠธ๋ฅผ ์ค„์ผ ์ˆ˜ ์ž‡๋Š” promise์™€ async๋ฅผ ์‚ฌ์šฉํ•˜์ž!

 

 

๋ณ€๊ฒฝ ํ›„

Promise

 const preventClick = () => {
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve(false);
      }, 200);
    });
  };
  
const handleLeftClick = async () => {
  
  preventClick().then((res)=>setDisabled(res))

preventClick์ด ์‹คํ–‰๋œ ํ›„(then) ๊ทธ ๊ฒฐ๊ณผ๋ฅผ resolve๋กœ ๋ฐ›์•„ setDisabled๋ฅผ ํ•ด์ค€๋‹ค

 

 

async  await

  const preventClick = () => {
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve(false);
      }, 200);
    });
  };
  
   const handleLeftClick = async () => {
   
    if (disabled) return;
    setDisabled(true);

    const boolean = await preventClick();
    setDisabled(boolean);

hadleClick ํ•จ์ˆ˜๋Š” ๋น„๋™๊ธฐ์ด๊ณ   preventClick ํ•จ์ˆ˜๊ฐ€ ์‹คํ–‰๋˜๋Š”๊ฑธ ๊ธฐ๋‹ค๋ ธ๋‹ค๊ฐ€ setDisabled๋ฅผ ์‹คํ–‰ํ•œ๋‹ค.

 

 

๋น„๋™๊ธฐ๋ฅผ ๋™๊ธฐ์ ์œผ๋กœ ๋ณด์—ฌ์ง€๊ธฐ ๋•Œ๋ฌธ์— ์ˆœ์„œ๊ฐ€ ๋ณด์ด๋Š” async await ์„ ์‚ฌ์šฉํ•˜๊ธฐ๋กœ ๊ฒฐ๋ก !

 

 

์ฐธ๊ณ (https://benjaminwoojang.medium.com/javascript-%EB%B9%84%EB%8F%99%EA%B8%B0-%EC%B2%98%EB%A6%AC%EB%A5%BC-%EC%9C%84%ED%95%9C-promise%EC%99%80-async-function-9b9913adb52)

 

 

 

setTimeout๋ณด๋‹ค ๋น„๋™๊ธฐ

๋ฐ˜๋ณต๋˜๋Š” ์ƒ์ˆ˜๋Š” ๋ณ€์ˆ˜๋กœ ์ง€์ •ํ•˜์—ฌ ์‚ฌ์šฉํ•˜๊ธฐ 

 


๐Ÿ“Œ ์นด์นด์˜ค map API React ์—์„œ ์‚ฌ์šฉํ•˜๊ธฐ 

์นด์นด์˜ค ๋งต API ์—ฐ๊ฒฐ์„ ํ•ด๋ณด์•˜๋‹ค.

ํ˜„์žฌ ๋‚˜๋Š” React ์—์„œ jsx ๋ฐฉ์‹์œผ๋กœ ํ•จ์ˆ˜ํ˜• Component ๋ฅผ ๋ Œ๋”๋งํ•˜๊ณ  ์žˆ๋‹ค.

json data์— ๋“ค์–ด์žˆ๋Š” ์—ฌ๋Ÿฌ๊ฐœ์˜ ์ˆ™์†Œ ์œ„์น˜ ์ •๋ณด๋ฅผ marker๋กœ ๋‚˜ํƒ€๋‚ด๋Š”๊ฒŒ ์ตœ์ข… ๋ชฉํ‘œ!!!

 

index.html (App๋ถˆ๋Ÿฌ์˜ค๋Š” ๊ณณ)

 <script
      type="text/javascript"
      src="//dapi.kakao.com/v2/maps/sdk.js?appkey=๋ณธ์ธ์˜Appํ‚ค&libraries=services"
    ></script>

RoomMap (์ง€๋„ component)

/*global kakao*/
const RoomMap = ({ roomData }) => {

  const placeArray = roomData
    ? roomData.accommodationList.map((v) => [v.latitude, v.longitude])
    : [[0, 0]];

  useEffect(() => {

    const container = document.getElementById('myMap');    
    const options = {
      center: new kakao.maps.LatLng(37.49091340540493, 127.03337782299037),
      level: 6,
      mapTypeId: kakao.maps.MapTypeId.ROADMAP,
    };
    
    const map = new kakao.maps.Map(container, options);

	//marker๋งŒ๋“œ๋Š” ํ•จ์ˆ˜ ์ƒ์„ฑ
    function displayMarker(place) {
      let marker = new kakao.maps.Marker({
        map: map,
        position: new kakao.maps.LatLng(place[0], place[1]),
      });
    }
    placeArray.map((loc) => displayMarker(loc));
  }, [placeArray]);

  return <MapContainer id="myMap"></MapContainer>;
};

//styled-components
const MapContainer = styled.div`
  width: 90%;
  height: 100vh;
  position: sticky;
  top: 0;
`;

export default RoomMap;

 

์‚ฝ์งˆํ–ˆ๋˜ ๋ถ€๋ถ„ 

 

1) AppKey ๋ฐœ๊ธ‰ ์‹œ React๋Š” ๋„๋ฉ”์ธ์„ ๋“ฑ๋กํ•ด์•ผํ•œ๋‹ค.!!!!!!

(์ด๊ฑธ ๋“ฑ๋กํ•˜์ง€ ์•Š์œผ๋ฉด 

kakao๋ฅผ ์ฐพ์ง€ ๋ชปํ•ด undefined๊ฐ€ ๋œจ๊ณ  -> " can't map in undefined maps  ...."  ๋ผ๋Š” ์˜ค๋ฅ˜๊ฐ€  ๋œจ๊ฒŒ ๋œ๋‹ค .. 

 

2) marker์—ฌ๋Ÿฌ๊ฐœ ๋„์šฐ๊ธฐ

marker๋Š” ๋ถ„๋ช…ํžˆ displayMarker๋ผ๋Š” ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด ์ œ๋Œ€๋กœ ์‹คํ–‰ํ–ˆ๋Š”๋ฐ ์™œ ์•ˆ๋๋ƒ๋ฉด, 

๋ฐ”๋กœ mock๋ฐ์ดํ„ฐ์˜ ์ง€๋„ ๋ฐ์ดํ„ฐ์˜ ์œ„์น˜๊ฐ€ ์ „๊ตญ๊ตฌ๋กœ ๋˜์–ด ์žˆ์—ˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค..^^ 

์ฝ”๋“œ๋ฅผ ๋ณด๋ฉด level6๋กœ ์ง€๋„ ์ •๋„๋ฅผ ์„ค์ •ํ•ด๋†“์•˜๋Š”๋ฐ ๊ทธ ๊ณณ์—๋Š” ํ•œ๊ตฐ๋ฐ (center)๋ฐ–์— ์—†๊ธฐ ๋•Œ๋ฌธ์— ๋ณด์ด์ง€ ์•Š๋Š”๋‹ค

->(์ด๊ฑธ๋กœ ํ•˜๋ฃจ์ฃ™์ผ ๊ณ ์ƒํ•จ..^^)_

 

 

๊ทธ๋ž˜๋„ ์นด์นด์˜ค๋งต์„ ์จ๋ณธ ๊ฒฝํ—˜์น˜ ํš๋“ ++!!

 

[์ฐธ๊ณ ](https://gingerkang.tistory.com/65)

 

 + customOverlay

import React, { useEffect, useMemo } from 'react';
import styled from 'styled-components';


/*global kakao*/
const RoomMap = ({ roomData }) => {

  useEffect(() => {
    const container = document.getElementById('myMap');
    const options = {
      center: new kakao.maps.LatLng(37.49091340540493, 127.03337782299037),
      level: 6,
      mapTypeId: kakao.maps.MapTypeId.ROADMAP,
    };
    const map = new kakao.maps.Map(container, options);

    const displayMarker = (place) => {
      const content = `<div class=marker>โ‚ฉ ${getRegex(place[2])}</div>`;
      new kakao.maps.CustomOverlay({
        map: map,
        position: new kakao.maps.LatLng(place[0], place[1]),
        content: content,
        yAnchor: 1,
      });
    };
    placeArray.map((loc) => displayMarker(loc));
  }, [placeArray]);
  //palceArray ๋Š” map ๋Œ๋ฆด ์ง€๋„ ๋ฐ์ดํ„ฐ

  return <MapContainer id="myMap"></MapContainer>;
};

const MapContainer = styled.div`
  width: 90%;
  height: 100vh;
  position: sticky;
  top: 0;
  .marker {
    padding: 4px 12px;
    background-color: ${({ theme }) => theme.colors.white};
    color: ${({ theme }) => theme.colors.gray2};
    box-shadow: 0px 0px 4px rgba(204, 204, 204, 0.5),
      0px 2px 4px rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(4px);
    font-weight: 600;
    font-size: ${({ theme }) => theme.fontSizes.XS};
    border-radius: 0.5rem;
    :hover {
      color: ${({ theme }) => theme.colors.magenta};
      background-color: ${({ theme }) => theme.colors.gray6};
    }
  }
`;

export default RoomMap;

cutomOverlay ๋ฅผ  ๋งŒ๋“ค์–ด  ๊ธฐ๋ณธ ํŒŒ๋ž€์ƒ‰ marker ๋Œ€์‹ ์— ๋‚ด๊ฐ€ ์›ํ•˜๋Š”  marker๋กœ ํ‘œ์‹œํ–ˆ๋‹ค.

content ์— ํ…œํ”Œ๋ฆฟ  ๋ฆฌํ„ฐ๋Ÿด๋กœ markerํ•ด์ค„ ๋Œ€์ƒ์„ ๋„ฃ์–ด์ฃผ์—ˆ๊ณ  class์ด๋ฆ„์„ ์ฃผ์–ด styled-components ์—์„œ ์Šคํƒ€์ผ์„ ์ง€์ •ํ–ˆ๋‹ค. 

[์ฐธ๊ณ ](https://apis.map.kakao.com/web/sample/markerWithCustomOverlay/ )

 


๐Ÿ“Œ์ด๋ฒคํŠธ ์ œ์–ด๋ฅผ ์ด์šฉํ•œ modal OFF 

์ง€๋‚œ ๋ฒˆ์—๋Š” modal OFF ์‹œ useRef๋ฅผ ์ด์šฉํ–ˆ์—ˆ๋Š”๋ฐ  ์ฐธ๊ณ (https://rrecoder.tistory.com/141?category=950210)

์ด๋ฒˆ์—๋Š” modal์„ div๋กœ ๊ฐ์‹ธ๋ฉฐ ํด๋ฆญ ์ด๋ฒคํŠธ ์‹œ ์ด๋ฒคํŠธ ๋ฒ„๋ธ”๋ง์„ ์ œ์–ดํ•˜๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ modal ์ฐฝ ์™ธ ํด๋ฆญ์‹œ ๋‹ซ๊ธฐ๋ฅผ ๊ตฌํ˜„ํ–ˆ๋‹ค.

์ด๋ฒˆ์—๋„ ์ œ๋‹ˆ์™€ ํ’€๋ฆฌ์ง€ ์•Š๋Š” ๋ฌธ์ œ๋ฅผ ๋‹จ์ˆœํžˆ ๋„˜๊ธฐ์ง€ ์•Š๊ณ  ๊ฐœ๋…์„ ๊ณต๋ถ€ํ•˜๊ณ  ํƒ๊ตฌํ•ด๋ณด๋ฉฐ ๋‚ด๋†“์€๊ฒฐ๋ก ์ด๋ผ ๋งค์šฐ ๋ฟŒ๋“ฏํ•˜๊ณ  ์žฌ๋ฐŒ์—ˆ๋‹ค.

 

๊ฒฐ๋ก ์ ์œผ๋กœ๋Š” ๋ชจ๋‹ฌ์ฐฝ ์™ธ  ์˜์—ญ ๋‹ซ๊ธฐ๋ฅผ ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋‘๊ฐ€์ง€๋กœ ์ •๋ฆฌํ–ˆ๋‹ค .

window.addEventListener๋ฅผ ์‚ฌ์šฉํ•˜๋Š” useRef :  https://rrecoder.tistory.com/141

 

[SidePJ] airdnd 1๋ถ€ - ํ”„๋กœ์ ํŠธ ์‹œ์ž‘ !

์ด๋ฒˆ์ฃผ ํ”„๋กœ์ ํŠธ๋Š” 3์ฃผ๊ฐ„ ๐Ÿ˜ŽJenny ๐ŸงDong ๊ณผ ํ•จ๊ป˜ํ•˜๊ฒŒ ๋˜์—ˆ๋‹ค ์ฒซ๋‚ ์€ ์—ญ์‹œ BE,FE ์™€ ์ปจ๋ฒค์…˜๊ณผ git repository๊ด€๋ฆฌ ๋“ฑ์„ ์ •ํ•˜๊ณ  Jenny์™€๋Š” Component๊ตฌ์กฐ๋ฅผ ์งฐ๋‹ค. โฌ‡๏ธ Component๊ตฌ์กฐ ์„ค๊ณ„๋„ https://app.diagrams...

rrecoder.tistory.com

closest ์™€ className์„ ์‚ฌ์šฉํ•˜๋Š” :   https://rrecoder.tistory.com/146

 

[SidePJ] React ๋ชจ๋‹ฌ ์˜์—ญ ๋ฐ– ํด๋ฆญ์‹œ ๋‹ซ๊ธฐ

๐Ÿ“Œ ์ „์ฒด ๊ตฌ์กฐ PayModalWrapper ๊ฐ€ RoomPayModal์„ ๊ฐ์‹ธ๊ณ  ์žˆ๋Š” ์ƒํƒœ ๋™์ž‘ : ์ˆ™์†Œ๋ฅผ ๋ˆ„๋ฅด๋ฉด ๋ชจ๋‹ฌ์ฐฝ์ด ๋œจ๊ณ  ๋ชจ๋‹ฌ์ฐฝ ์™ธ์˜ ์˜์—ญ ํด๋ฆญ ์‹œ ๋ชจ๋‹ฌ์ฐฝ์ด ๋‹ซํžŒ๋‹ค. ๐Ÿ“Œ ์ฝ”๋“œ handlePayModalOff ํ•จ์ˆ˜๋กœ ๋ชจ๋‹ฌ ์™ธ ์˜์—ญ ํด๋ฆญ ์‹œ.

rrecoder.tistory.com

 


๐Ÿ“ŒuseMemo๋ฅผ ์ด์šฉํ•œ ์ตœ์ ํ™”

๋ณ€๊ฒฝ ์ „ ์ฝ”๋“œ๋กœ ๊ตฌํ˜„์‹œ์— React ๊ฒฝ๊ณ  ๋ฉ”์„ธ์ง€๊ฐ€ ๊ณ„์† ๋–ด์—ˆ๋‹ค.

"palceArray๋Š” ๋งค๋ฒˆ ์žฌ๋ Œ๋”๋ง ๋œ๋‹ค๋Š” ๋ง, ์ฆ‰ useMemo๋ฅผ ์‚ฌ์šฉํ•ด๋ผ"

 

 

 

<RoomMap.jsx> ๋ณ€๊ฒฝ ์ „ 

import React, { useEffect } from 'react';
import styled from 'styled-components';


const RoomMap = ({ roomData }) => {
 
  const placeArray = roomData
    ? roomData.accommodationList.map((v) => [v.latitude, v.longitude])
    : [[0, 0]];

  useEffect(() => {
    const container = document.getElementById('myMap');
   
    placeArray.map((loc) => displayMarker(loc));
  }, [placeArray]);

  return <MapContainer id="myMap"></MapContainer>;
};

<RoomMap.jsx> ๋ณ€๊ฒฝ ํ›„ 

import React, { useEffect, useMemo } from 'react';
import styled from 'styled-components';

const RoomMap = ({ roomData }) => {
  const placeArray = useMemo(
    () =>
      roomData
        ? roomData.accommodationList.map((v) => [v.latitude,v.longitude,])
        : [[0, 0]],
    [roomData]
  );

  useEffect(() => {
    const container = document.getElementById('myMap');
   
    //์ค‘๋žต...
    
    placeArray.map((loc) => displayMarker(loc));
  }, [placeArray]);

  return <MapContainer id="myMap"></MapContainer>;
};



export default RoomMap;

RoomMap ์•ˆ์—์„œ ์ž์ฒด ์ƒ์„ฑํ•˜๋Š” ๋ณ€์ˆ˜๋Š” useEffect์˜ ์˜์กด์„ฑ ๋ฐฐ์—ด์— ๋„ฃ๋Š” ์˜๋ฏธ๊ฐ€ ์—†๋‹ค

 placeArray๋Š” <RoomMap> ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์žฌ๋ Œ๋”๋ง ๋ ๋•Œ๋งˆ๋‹ค ๋‹ค์‹œ ์ƒ์„ฑ๋˜๊ธฐ ๋•Œ๋ฌธ์— (์ƒˆ ๋ฉ”๋ชจ๋ฆฌ ์ฃผ์†Œ์— ํ• ๋‹น) ๋ฌด์กฐ๊ฑด useEffect ๊ฐ€ ์‹คํ–‰๋˜๊ฒŒ ๋œ๋‹ค. 

 

๊ทธ๋ ‡๋‹ค๋ฉด ? useMemo๋ฅผ ์จ๋ณด์ž 

RoomMap์•ˆ์—์„œ ์ƒ์„ฑ๋˜๋Š” ๋ณ€์ˆ˜ placeArray๋ฅผ useMemo๋กœ ๊ฐ์‹ธ๊ณ  useMemo์˜ ์˜์กด์„ฑ ๋ฐฐ์—ด์— roomData๋ฅผ ๋„ฃ์–ด 

roomData๊ฐ€ ๋ณ€ํ•˜์ง€ ์•Š์œผ๋ฉด ํ•ด๋‹น๊ฐ’์€ (placeArray) ๊ตณ์ด ์žฌ๋ Œ๋”๋ง ํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ์˜๋ฏธ์—†๋Š” ๋ Œ๋”๋ง์„ ๋ฐฉ์ง€ํ•˜๊ฒŒ ๋œ๋‹ค!!! 

 

๐Ÿ˜ฎuseEffect์˜ ์˜์กด์„ฑ ๋ฐฐ์—ด์— ๋“ค์–ด๊ฐ€๋Š” ๊ฑด?

props๋กœ ์ „๋‹ฌ๋ฐ›์€ ๊ฐ’ or Hook์œผ๋กœ ๊ด€๋ฆฌ๋˜๋Š” ์ƒํƒœ๊ฐ’ , ๋ Œ๋”๋ง ๋˜๋ฉด์„œ ๋ณ€ํ•˜๋Š” ๊ฐ’


๐Ÿฅฐ ๋งˆ๋ฌด๋ฆฌ 

๊ทธ ์™ธ OAuth ๊ตฌํ˜„๋„ ์ง„ํ–‰ํ•˜๊ณ  3์ฃผ๊ฐ„์˜ ํ”„๋กœ์ ํŠธ๋ฅผ ๋งˆ๋ฌด๋ฆฌํ•˜๊ฒŒ ๋˜์—ˆ๋‹ค.

์ด๋ฒˆํ”„๋กœ์ ํŠธ๋Š” ๊ณต๋ถ€์™€ ๊ตฌํ˜„์ด ๋„ˆ๋ฌด ์กฐํ™”๋กœ์› ์–ด์„œ ํ–‰๋ณตํ–ˆ๋‹ค. ํ”„๋กœ์ ํŠธํ•˜๋ฉด์„œ ์ž˜ํ•œ์ ๊ณผ ์•„์‰ฌ์šด์ ์„ ์ ์œผ๋ฉฐ ๋งˆ๋ฌด๋ฆฌ ํ•ฉ๋‹ˆ๋‹ค.

 

โค๏ธ ์ž˜ํ•œ ์ 

1)  ๊ตฌํ˜„์—๋งŒ ์น˜์ค‘ํ•˜์ง€ ์•Š๊ณ  ๋ง‰ํžˆ๋Š” ๋ถ€๋ถ„์ด ์žˆ์„ ๋•Œ ํ•™์Šตํ•˜๋ฉฐ ๊ตฌํ˜„ํ•œ๊ฒƒ

 : useMemo์˜ ์‚ฌ์šฉ์ด๋‚˜ , modal์ฐฝ ์ข…๋ฃŒ๋ฅผ ๊ตฌํ˜„ํ•  ๋•Œ ๋‹จ์ˆœํžˆ ๊ตฌํ˜„์ด ๋˜๊ฒŒ ๊ธ‰ํ•˜๊ฒŒ ์ง„ํ–‰ํ•˜์ง€ ์•Š๊ณ , Jenny์™€ ์—ด๋ค ํ† ๋ก ์„ ํ†ตํ•ด ์ด๋ฒคํŠธ ๋ฒ„๋ธ”๋ง์—๋Œ€ํ•ด์„œ๋„ ๊ณต๋ถ€ํ•˜๊ณ  ์ฐจ๋ถ„ํ•˜๊ฒŒ ๊ณ ์ณ๋‚˜๊ฐ”๋‹ค. ๋„ˆ๋ฌด ์ข‹์•˜๋‹ค.

 

2) ๋ฆฌ์•กํŠธ ์ฝ˜์†”์งฑ์ด ๊น”๋”ํ•ด!

๋ฆฌ์•กํŠธ ์ฝ˜์†”์ฐฝ์˜ ๋ชจ๋“  ๊ฒฝ๊ณ ์‚ฌํ•ญ์„๋ง๋”ํžˆ ํ•ด๊ฒฐํ–ˆ๋‹ค . (์„ ์–ธํ•˜๊ณ  ์•ˆ์“ด๊ฒƒ, ๋ถˆํ•„์š”ํ•œ ๋ Œ๋”๋ง์— ๊ด€ํ•œ ์‚ฌํ•ญ ๋“ฑ๋“ฑ ) 

 

3) ๋…ธ์…˜์— ๊ธฐํš์„œ ์ •๋ฆฌํ•ด์„œ ๋ฐœํ‘œํ•˜๋Š” ๋ฐฉ์‹

์ •๋ฆฌ๋ณ‘์ด ์‹ฌํ•ด์„œ ์ด๋ฒˆ์— ๋…ธ์…˜์— ์ •๋ฆฌํ•ด์„œ ๋ฐœํ‘œํ•ด๋ณด์•˜๋Š”๋ฐ ๋„ˆ๋ฌด ์ข‹์•˜๋‹ค.. ์ตœ๊ณ 

๊ฐ€์žฅ ์ข‹์•˜๋˜ ์ ์€, ๊ธฐํš์„œ์˜  ์ƒ์„ธ ๊ธฐ๋Šฅ์„ ๋น ๋ฅด๊ณ  ์ƒ์„ธํ•˜๊ฒŒ ์ž๋ž‘ํ•  ์ˆ˜ ์žˆ๋‹ค๋Š”์ . ๋‚ด๊ฐ€ ๊ณ ์ƒํ•œ ๋ถ€๋ถ„์„ ๋น ๋œจ๋ฆฌ์ง€ ์•Š๊ณ  ์ž๋ž‘ํ•  ์ˆ˜ ์žˆ๋Š”๊ฒŒ ์–ผ๋งˆ๋‚˜ ํฐ ํ–‰๋ณต์ธ๊ฐ€~~~๐Ÿ˜Œ

 

๐Ÿ’™ ์•„์‰ฌ์šด์  

1) ์ฝ”๋“œ ์งœ๊ธฐ ์ „ ์ข‹์€ ์ฝ”๋“œ๋ฅผ ์œ„ํ•œ ๊ทœ์น™์„ ์ด์•ผ๊ธฐ ํ•ด๋ณด์ง€ ์•Š์€ ๊ฒƒ 

ํ”„๋กœ์ ํŠธ ํ›„๋ฐ˜๋ถ€์— ๊ฐ€์„œ ๋ฆฌํŒฉํ† ๋งํ•˜๋ฉด์„œ ๋งŽ์ด ์ˆ˜์ •ํ–ˆ์ง€๋งŒ  ์ข‹์€ ์ฝ”๋“œ๋ฅผ ์œ„ํ•œ ๊ณ ๋ฏผ์„ ์ •๋ฆฌํ•ด๋ณด์ง€ ๋ชปํ•œ๊ฒƒ์ด ์•„์‰ฝ๋‹ค.

์ข‹์€ ์ฝ”๋“œ๋ฅผ ์œ„ํ•ด ๋…ธ๋ ฅํ–ˆ๋˜ ์ ๋„ ์ •๋ฆฌํ•ด์„œ ๋‹ค์Œ ํ”„๋กœ์ ํŠธ  ํ˜น์€ ๋‹ค๋ฅธ ํŒ€์›๊ณผ์˜ ์ƒํ™ฉ์— ์ ์šฉํ•ด๋ณด๋ฉฐ ์ฐจ๊ณก์ฐจ๊ณก ์ข‹์ฝ”(?)๋Šฅ๋ ฅ์„์Œ“๊ณ ์‹ถ๋‹ค.

 

2) ์‹ ๊ธฐ์ˆ  ๋„์ž…์— ๊ฒ๋จน์—ˆ๋˜ ์ 

ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ์™€ ๋ฆฌ์ฝ”์ผ์„ ์ ์šฉํ•˜์ง€ ๋ชปํ•œ์ ์ด ๊ณ„์†๊ณ„์† ํ•œ์œผ๋กœ ๋‚จ๋Š”๋‹ค. ๋‹ค์Œ ํ”„๋กœ์ ํŠธ ๋•Œ์—๋Š” ์‹ ๊ธฐ์ˆ ์— ๋ถ€๋”ชํžˆ๊ณ  ๊นจ์ ธ ๋ณผ๊ฒƒ์ด๋‹ค. 

 

์ด๋ฒˆ ํ”„๋กœ์ ํŠธ๋ฅผ ํ•จ๊ป˜ํ•ด์ค€ Dong๊ณผ Jenny์—๊ฒŒ๋„ ๊ฐ์‚ฌ์˜ ๋ง์„ ์ „ํ•˜๋ฉฐ ๋งˆ๋ฌด๋ฆฌํ•ฉ๋‹ˆ๋‹ค.  ๋งŒ๋‚˜์„œ ๋ฐ˜๊ฐ€์› ๊ณ  ๋˜๋ด…์‹œ๋‹ค~

 

 

 

 

๐Ÿพ ์ด๋ฒˆ ํ”„๋กœ์ ํŠธ๋ฅผ ํ†ตํ•ด ๋ฐฐ์šด ์ข‹์€ ์ฝ”๋“œ๋ฅผ ํ–ฅํ•œ ํ•œ๊ฑธ์Œ

 

1. Component์˜ ์†์„ฑ์—๋Š” ๋งค์ง๋„˜๋ฒ„,์ŠคํŠธ๋ง์ด ๋“ค์–ด๊ฐ€์ง€ ์•Š๋Š”๋‹ค.

: ์ž‘์€ ๋ถ€๋ถ„์ด๋ผ ์ƒ๊ด€ ์—†์„ ๊ฒƒ์ด๋ผ ์ƒ๊ฐํ–ˆ์ง€๋งŒ  ์ด๋Ÿฐ ์ž‘์€ ๊ฒƒ๋“ค์ด ์ฝ”๋“œ์˜ ๊ฐ€๋…์„ฑ์„ ๋–จ์–ด๋œจ๋ฆฐ๋‹ค.

 

2 ์ง€๊ธˆ ๋ฐ”๋กœ ์‚ฌ์šฉํ•˜์ง€ ์•Š์„ ๋Œ€์ƒ์€ ๋ฏธ๋ฆฌ ๋งŒ๋“ค์ง€ ๋ง์ž.

import {useEffect , useRef... } ์ฒ˜๋Ÿผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์„ ๊ฒƒ์€ ์ฒ˜์Œ๋ถ€ํ„ฐ ์“ฐ์ง€ ์•Š๋Š” ์Šต๊ด€!

 

3.  ํ•จ์ˆ˜๋‚˜ ๋ณ€์ˆ˜๋กœ ๋ฏธ๋ฆฌ ๋งŒ๋“ค์–ด, ์—ฐ์‚ฐ์„ ์ธ๋ผ์ธ์— ๋‘์ง€ ์•Š๋Š”๋‹ค.

1.๋ฒˆ๊ณผ ๋น„์Šทํ•œ ๋งฅ๋ฝ์ด์ง€๋งŒ , ์ž๊พธ๋งŒ Component ๋ Œ๋”๋ง ๋ถ€๋ถ„์— ์—ฐ์‚ฐ์„ ๋‘๋Š” ๋ฒ„๋ฆ‡์ด ์žˆ์—ˆ๋‹ค.

๊ฐ€๋…์„ฑ์ด ํ˜„์ €ํžˆ ๋–จ์–ด์ง€๋‹ˆ ํ•„์ˆ˜์ ์ด์ง€ ์•Š์œผ๋ฉด ๋ฏธ๋ฆฌ ๋งŒ๋“ค์–ด์„œ ๊ฐ€์ ธ์˜ค์ž.

 

4. ๋ Œ๋”๋ง ์‹œ ์‚ผํ•ญ์—ฐ์‚ฐ์ž๋ณด๋‹จ && ์‚ฌ์šฉ

์‚ผํ•ญ์—ฐ์‚ฐ์ž๋Š” ์ฝ”๋“œ๊ฐ€ ํ•œ์ค„์ผ ๊ฒฝ์šฐ์— ์‚ฌ์šฉํ•˜๊ณ  ๊ทธ ์ด์ƒ์ด ๋œ๋‹ค๋ฉด ์กฐ๊ฑด๋ฌธ์œผ๋กœ ๋นผ๋Š” ๊ฒƒ์ด ๊ฐ€๋…์„ฑ์— ์˜คํžˆ๋ ค ์ข‹๋‹ค.

์–ด๋–ค ์กฐ๊ฑด์ผ๋•Œ๋งŒ ๋ Œ๋”๋งํ•œ๋‹ค? -> && ์—ฐ์‚ฐ์ž ์‚ฌ์šฉ์œผ๋กœ ์ฒ˜๋ฆฌ 

 

5. ๋ณ€์ˆ˜๋ช…์€ ์ฒซ ์ˆœ๊ฐ„ ๊ณ ๋ฏผํ•˜์ž

์ผ๋‹จ ๋˜์ž๋ผ๋Š” ๋งˆ์ธ๋“œ๋กœ ๋งŒ๋“  ๋ณ€์ˆ˜๋ช…์€ ๋‚˜์ค‘์— ์žŠ๊ธฐ ์‰ฝ์ƒ! 

์ฒ˜์Œ๋งŒ๋“ค ๋•Œ๋ถ€ํ„ฐ ๊ณ ๋ฏผํ•˜์ž . ๊ฐ™์€ ๋ ˆ๋ฒจ(?)์—์„œ ๋น„์Šทํ•œ ์šฉ๋„๋กœ ์‚ฌ์šฉ๋˜๋Š” ๋ณ€์ˆ˜๋ช…๋“ค์—๊ฒŒ ์ผ์ •ํ•œ ๊ทœ์น™์„ ๋ถ€์—ฌํ•˜๋Š” ๊ฒƒ๋„ ๋‚˜๋ฆ„์˜ ๋ฐฉ๋ฒ•

 

6. ํ•จ์ˆ˜๋Š” ํ•˜๋‚˜์˜ ๊ธฐ๋Šฅ๋งŒ

ํ•จ์ˆ˜์— ์กฐ๊ฑด or type์ด ๋‹ฌ๋ ค ๋‹ค๋ฅธ ๊ธฐ๋Šฅ์„ ์ˆ˜ํ–‰ํ•˜๊ฒŒ ํ•˜์ง€ ๋ง๊ณ 

์—ฌ๋Ÿฌ๊ฐœ์˜ ํ•จ์ˆ˜๊ฐ€ ์ƒ๊ธฐ๋”๋ผ๊ณ  ํ•˜๋‚˜์˜ ๊ธฐ๋Šฅ์„ ํ•˜๋Š” ์‹ฌํ”Œํ•œ ํ•จ์ˆ˜๊ฐ€ ์‹ฌํ”Œํ•œ ์ฝ”๋“œ๋ฅผ ๋งŒ๋“ ๋‹ค.

 

7. ํ•„์š”ํ•˜์ง€ ์•Š์€ ๊ธฐ๋Šฅ์„ ๋ฏธ๋ฆฌ ๊ตฌํ˜„ํ•˜์ง€ ๋ง์ž

์ง€๋‚˜์น˜๊ฒŒ ๋ฏธ๋ž˜ ์ง€ํ–ฅ์ ์ธ ์ฝ”๋“œ๋Š” ์ฝ”๋“œ์˜ ๋ณต์žก์„ฑ์„ ์ฆ๊ฐ€์‹œํ‚ฌ ๋ฟ์ด๋‹ค . 

๋‚˜์ค‘์— ์“ธ๊ฒƒ๊ฐ™์€๋ฐ? ํ•˜๋Š” ๊ฑด ๋ฏธ๋ฆฌ ๋งŒ๋“ค์ง€ ๋ง๊ณ  ์“ธ ๋•Œ ๋งŒ๋“ค์ž.

๋Œ“๊ธ€