[TIL] 22.10.12 ๐Ÿ’Œ

yesยท2022๋…„ 10์›” 12์ผ
0

TIL ๐Ÿ’Œ

๋ชฉ๋ก ๋ณด๊ธฐ
36/55
post-thumbnail
post-custom-banner
  • ๋ฉด์ ‘ ์ค€๋น„
  • ํ”„๋กœ์ ํŠธ ์ง„ํ–‰
    • ํ•™๊ต ์ฐพ๊ธฐ ๋ฒ„ํŠผ ๋ˆ„๋ฅธ ์ดํ›„ ๋ชจ๋‹ฌ ์ œ์ž‘
    • ํ•™๊ต open API ์—ฐ๋™

๊ณต๋ถ€๋ฅผ ํ•˜๋ฉด ํ• ์ˆ˜๋ก ์•„๋Š” ๊ฒƒ์€ ๋งŽ์•„์ง€์ง€๋งŒ, ๋‹ค์‹œ ๊ณต๋ถ€ํ–ˆ๋˜ ๋‚ด์šฉ์„ ๊ณต๋ถ€ํ•  ๋•Œ ๋‚˜๋Š” ์™œ ์ด๋ ‡๊ฒŒ ๊ธฐ์–ต๋ ฅ์ด ์•ˆ ์ข‹์€๊ฐ€? ์ฒ˜์Œ์— ์ด ๋‚ด์šฉ์— ๋Œ€ํ•ด์„œ ๊ณต๋ถ€ํ•  ๋•Œ ๋” ๊นŠ๊ฒŒ ํŒŒ๊ณ ๋“ค๊ณ  ๊ณต๋ถ€ํ–ˆ์–ด์•ผ ๋๋‚˜? ์ด๋Ÿฐ ํ˜„ํƒ€๊ฐ€ ์ฐพ์•„์˜จ๋‹ค. ๋ชจ๋ฅด๋Š” ๊ฒƒ์„ ๋ถ€๋„๋Ÿฌ์›Œํ•˜์ง€ ๋ง๊ณ  ๋” ๊นŠ๊ฒŒ ๊ณ ๋ฏผํ•˜๊ณ  ๋” ๊ณต๋ถ€ํ•˜์ž. ๋‘ ๋ฒˆ ์„ธ ๋ฒˆ ๋‹ค์‹œ ๋ด์„œ ๋‚ด ๊ฒƒ์œผ๋กœ ๋งŒ๋“ค๋ฉด ๋œ๋‹ค.


์–ด๋–ป๊ฒŒ ํ•˜๋ฉดย ์žฌ์‚ฌ์šฉ๊ฐ€๋Šฅํ•œย ์ปดํฌ๋„ŒํŠธ๋ฅผ ๊ฐ๊ฐ ๋‹ค๋ฅธ use case๋“ค์— ๋งž๋„๋ก ๋งŒ๋“ค ์ˆ˜ ์žˆ์„๊นŒ?

๋ชจ๋‹ฌ ์ปดํฌ๋„ŒํŠธ ์žฌ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋ถ„๋ฆฌ

๊ณ„๊ธฐ

๊ธฐ์กด์—๋Š” Modal ์ปดํฌ๋„ŒํŠธ์˜ ์žฌ์‚ฌ์šฉ์„ฑ์„ ๊ณ ๋ คํ•˜์ง€ ์•Š๊ณ  ์„ค๊ณ„.
๋”ฐ๋ผ์„œ, Modal ์ปดํฌ๋„ŒํŠธ ์žฌ์‚ฌ์šฉ์ด ๋ถˆ๊ฐ€๋Šฅ.

๋ณ€ํ™” ๊ณผ์ •

ModalLayout์˜ ๋„ˆ๋น„๋Š” ๋™์ผํ•˜๋ฏ€๋กœ ๊ณ ์ •ํ•˜๊ณ , height๋ฅผ props๋กœ ๋„˜๊ฒจ๋ฐ›์•„ ๋†’์ด ์กฐ์ ˆ.

๋ชจ๋‹ฌ์˜ ์ƒํƒœ(์—ด๊ณ , ๋‹ซ๊ธฐ)๋Š” useModalControl๋กœ ๋ถ„๋ฆฌ

ModalLayout์ด ํ•„์š”ํ•œ ์ปดํฌ๋„ŒํŠธ์—์„œ useModalControl hooks์™€ ModalLayout ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉ.

ModalLayout ๋‚ด๋ถ€์˜ ๊ฐ๊ฐ ๋‹ค๋ฅธ ๋‚ด์šฉ๋ฌผ์€ children์œผ๋กœ ๋„˜๊ฒจ๋ฐ›์•„ ์ง‘์–ด ๋„ฃ๊ธฐ.

์ถ”๊ฐ€๋กœ ๊ณ ๋ฏผํ•ด์•ผํ•  ์‚ฌํ•ญ

๋‹ซ๊ธฐ ๋ฒ„ํŠผ

๋‹ซ๊ธฐ ๋ฒ„ํŠผ์„ flot์†์„ฑ์„ ์‚ฌ์šฉํ•ด์„œ cssํ๋ฆ„์—์„œ ๋น ์ง€๊ฒŒ ์ œ์ž‘ํ–ˆ์Œ (๊ธฐ์กด)

๋ชจ๋‹ฌ ๋ ˆ์ด์•„์›ƒ์ด ํ•„์š”ํ•œ ์ปดํฌ๋„ŒํŠธ๋“ค์€ ๋ชจ๋‘ ๋‹ซ๊ธฐ ๋ฒ„ํŠผ์ด ํ•„์š”ํ•จ ํ•˜์ง€๋งŒ ํ•˜๋‚˜๊ฐ€ ์œ„์น˜๊ฐ€ ๋‹ค๋ฆ„

์ƒ๊ฐ

  1. ๋‹ซ๊ธฐ ๋ฒ„ํŠผ์ด ํ•„์š”ํ•œ ์ง€ boolean๊ฐ’์œผ๋กœ ๋„˜๊ฒจ๋ฐ›์•„ ๋™์  ๋ Œ๋”๋ง?
  2. ๋‹ซ๊ธฐ ๋ฒ„ํŠผ์„ ์•„์˜ˆ ModalLayout์—์„œ ์ œ๊ฑฐ?

์–ป์€ ์ 

์ปดํฌ๋„ŒํŠธ๋ฅผ ์„ค๊ณ„ํ•  ๋•Œ ์ฒ˜์Œ๋ถ€ํ„ฐ ๋” ์žฌ์‚ฌ์šฉ์„ฑ๊ณผ ํ™•์žฅ์„ฑ์„ ๊ณ ๋ คํ•ด์„œ ๊นŠ๊ฒŒ ๊ณ ๋ฏผํ•˜๊ณ  ์ฝ”๋“œ๋ฅผ ์งœ์ž.


ํ•™๊ต ๊ฒ€์ƒ‰ api

๊ตฌํ˜„ ๊ณผ์ •

ํ•™๊ต ์ด๋ฆ„ ์ž…๋ ฅ๋ž€ input์— ์ž…๋ ฅ ์ดํ›„ submit event listen์‹œ input์— value ๊ฐ’์„ api url

  1. ํ•™๊ต ์ด๋ฆ„ ์ž…๋ ฅ input์— ์ž…๋ ฅ
    • input value ๊ฐ’์€ state๋กœ ๊ด€๋ฆฌ [searchSchool, setSearchSchool]
  2. ํ•™๊ต ์ด๋ฆ„ ์ž…๋ ฅ form submit event ๋ฐœ์ƒ ์‹œ
    • data fetch
    • url ์‹ ์ฒญ์ธ์ž SCHUL_NM=searchSchool
    • setSearchSchool(โ€โ€) input value ๊ฐ’ ์ดˆ๊ธฐํ™”

Think

ํ˜„์žฌ ์ด ๊ตฌํ˜„๊ณผ์ •์€ ํ”„๋ก ํŠธ์—”๋“œ์—์„œ ์ง์ ‘ open api๋กœ data๋ฅผ fetchํ•˜๊ฒŒ ๋œ๋‹ค.

ํ•˜์ง€๋งŒ, ์‹ ์ฒญ์ธ์ž๋กœ ๋„ฃ์–ด์ฃผ๋Š” SCHUL_NM์„ ๋ฐฑ์—”๋“œ api url๋กœ ๋„˜๊ฒจ์ฃผ์–ด์„œ ๋ฐฑ์—”๋“œ์—์„œ open api๋กœ ํ•ด๋‹น data๋ฅผ fetch๋ฐ›์•„ ๋‹ค์‹œ ํ”„๋ก ํŠธ๋กœ ๋„˜๊ฒจ์ฃผ๋Š” ๋ฐฉ์‹๋„ ์žˆ์„ ๊ฒƒ ๊ฐ™๋‹ค.

์ฒซ ๋ฒˆ์งธ๋Š” ๋ฐฑ์—”๋“œ์™€ ์†Œํ†ต ์—†์ด ๋ฐ”๋กœ ์ ‘๊ทผ, ๋‘ ๋ฒˆ์งธ๋Š” ๋ฐฑ์—”๋“œ์™€ ์†Œํ†ต ์žˆ์Œ

๋ญ๊ฐ€ ๋” ํšจ์œจ์ ์ธ๊ฐ€?

ํ˜„์žฌ๋Š” ํ™•์‹คํ•˜์ง€ ์•Š์ง€๋งŒ ๋ฐ”๋กœ url์— ์ ‘๊ทผํ•˜๊ณ  data๋ฅผ ๊ฐ€๊ณตํ•  ํ•„์š”์—†์ด ๋„ฃ์–ด์ฃผ๋ฉด ๋ผ์„œ ๋ฐฑ์—”๋“œ์™€ ์†Œํ†ต ์—†๋Š” ์ดํ”ผ์…œ ๋ฐฉ๋ฒ•์„ ํƒํ–ˆ๋‹ค. ํ•„์š”์—†๋Š” data๋„ fetchํ•ด์„œ state์— ๋„ฃ๊ฒŒ ๋˜๋Š”๋ฐ

์„ฑ๋Šฅ์— ์กฐ๊ธˆ์ด๋ผ๋„ ์˜ํ–ฅ์ด ์žˆ์„๊นŒ?

๋ฐฑ์—”๋“œ์—์„œ ๋‚ด๊ฐ€ ํ•„์š”ํ•œ SD_SCHUL_CODE, SCHUL_NM, LCTN_SC_NM ๊ฐ’๋“ค ๋ง๊ณ  ๋‹ค๋ฅธ ํ‚ค๋Š” ๋นผ์„œ ๋‹ค์‹œ ํ”„๋ก ํŠธ์—๊ฒŒ ์ฃผ๋ฉด์€ ํ”„๋ก ํŠธ์—๋Š” data์–‘์ด ๋” ์ ์–ด์ง€๊ฒŒ ๋˜์–ด์„œ ์ข‹์„ ๊ฑฐ ๊ฐ™๋‹ค๊ณ  ์ƒ๊ฐ์ด ๋“ ๋‹ค.

์กฐ์‚ฌ๋ฅผ ๋” ํ•ด์„œ ์ด ๋ถ€๋ถ„์— ๋Œ€ํ•ด์„œ ์ˆ˜์ •ํ•ด๋ณด๋„๋ก ํ•˜๊ฒ ๋‹ค.

post-custom-banner

0๊ฐœ์˜ ๋Œ“๊ธ€