[ionic6/React] ๐Ÿšซ SyntaxError: Unexpected end of JSON input

xeptemberยท2022๋…„ 6์›” 30์ผ
0
post-thumbnail

๐Ÿšซ SyntaxError: Unexpected end of JSON input

๐Ÿšซ Unhandled Rejection (SyntaxError): Unexpected end of JSON input

Ionic6์™€ React v17์„ ์‚ฌ์šฉํ•ด ํ•˜์ด๋ธŒ๋ฆฌ๋“œ ์•ฑ์„ ๋งŒ๋“ค๊ณ  ์žˆ์—ˆ๋Š”๋ฐ
ํŠน์ • ํŽ˜์ด์ง€์˜ ํŠน์ • API 3๊ฐœ๋งŒ ์œ„์™€ ๊ฐ™์€ ์—๋Ÿฌ๊ฐ€ ๋‚˜๊ณ  ์žˆ์—ˆ๋‹ค

๋” ์•Œ ์ˆ˜ ์—†๋Š”๊ฑด ์—๋Ÿฌ๊ฐ€ ๋‚ ๋•Œ๋„, ์•ˆ๋‚ ๋•Œ๋„ ์žˆ๊ณ 
์—๋Ÿฌ๊ฐ€ ๋˜‘๊ฐ™์ด ๋‚˜๋„ catch๋กœ ์žก์€ ์ฝ˜์†”๋กœ๋งŒ ์—๋Ÿฌ๊ฐ€ ๋œฐ ๋•Œ๋„ ์žˆ๊ณ  ์•„๋‹˜ ์•„์˜ˆ ํŽ˜์ด์ง€ ์ ‘๊ทผ์ด ๋ถˆ๊ฐ€ํ•˜๋„๋ก ์—๋Ÿฌ๊ฐ€ ๋œฐ ๋•Œ๋„ ์žˆ์—ˆ๋‹ค

์•„์˜ˆ ์—๋Ÿฌ๊ฐ€ ๋‚˜๋ฒ„๋ฆฌ๋ฉด ๋ชจ๋ฅด๊ฒ ๋Š”๋ฐ ๊ฐ„ํ—์ ์œผ๋กœ ๋ฐœ์ƒํ•˜๊ณ  ์žˆ๋‹ค๋ณด๋‹ˆ ์›์ธ์„ ์ข…์žก๊ธฐ๊ฐ€ ๋„ˆ๋ฌด ์–ด๋ ค์› ๋‹ค
๊ฒ€์ƒ‰์„ ๋งŽ์ด ํ•ด๋ดค๋Š”๋ฐ ์ผ๋‹จ ์—๋Ÿฌ์ƒ์—์„œ syntax error๋ผ๊ณ  ๋œจ๊ธด ํ•˜์ง€๋งŒ ์•„๋ฌด๋ฆฌ ๋ด๋„ ๋ฌธ๋ฒ• ์—๋Ÿฌ๋Š” ์ „ํ˜€ ์•„๋‹ˆ์˜€๊ณ  api response์‹œ์— ๋ฐ›์€ ๋ฐ์ดํ„ฐ๊ฐ€ jsonํƒ€์ž…์ด ์•„๋‹ˆ๋ผ html ํƒ€์ž…์ด๋ผ๋Š”๋‘ฅ.. ๋ญ ์ด๋Ÿฐ ์ €๋Ÿฐ ์–˜๊ธฐ๊ฐ€ ์žˆ๊ธด ํ–ˆ๋Š”๋ฐ ๋‹ค๋ฅธ api๋“ค์€ ๋ชจ๋‘ ๋ฉ€์ฉกํ•œ๊ฑธ๋กœ ๋ด์„œ ๊ทธ ๋ฌธ์ œ๋Š” ์•„๋‹ˆ์˜€๋˜ ๋“ฏ ์‹ถ๋‹ค.

๊ทผ๋ฐ ์™œ syntax error๋ผ๊ณ  ๋œจ๋Š”๊ฑด์ง€.. ?; ์ด๊ฑด ๋ชจ๋ฅด๊ฒ ๋‹ค

๊ฒฐ๋ก ์€ ์•„์ด์˜ค๋‹‰์—์„œ ์ œ๊ณตํ•˜๋Š” lifecycle์„ ํ†ตํ•ด ํ•ด๊ฒฐํ–ˆ๋‹ค

์—๋Ÿฌ๊ฐ€ ๋‚˜๋˜ ํŠน์ • api 3๊ฐœ๋Š” ๋‹ค๋ฅธ api๋“ค๊ณผ์˜ ์˜์กด์„ฑ์ด ์žˆ๋˜๊ฒƒ๋“ค์ด์˜€๋Š”๋ฐ useEffect๋กœ api๋ฅผ ํ˜ธ์ถœํ•˜๋‹ˆ ์˜์กด์„ฑ์ด ์žˆ๋˜ ๋‹ค๋ฅธ api๋“ค์ด ํ˜ธ์ถœ๋˜๋Š” ์‹œ์ ๊ณผ ๋ฌธ์ œ๋‚˜๋˜ api๋“ค์˜ ํ˜ธ์ถœ๋˜๋Š” ์‹œ์ ์ด ์‹ฑํฌ๊ฐ€ ๋งž์ง€ ์•Š์•˜์—ˆ๋˜๋“ฏ ๐Ÿ˜Ž? ์ถ”์ธก์ด๊ธด ํ•˜๋‹ค๋งŒ ใ…‹ใ„ทใ…‹ใ„ท

๊ทธ๋ž˜์„œ useEffect ๋กœ ๋˜์–ด์žˆ๋˜ ๋ถ€๋ถ„์„ useIonViewWillEnter๋กœ ๋ฐ”๊ฟ”์„œ ์‹œ๋„ํ–ˆ์ง€๋งŒ ๊ฒฐ๊ณผ๋Š” ๋™์ผํ–ˆ๋‹ค
์–ด์ฐŒ๋๋“  ํŽ˜์ด์ง€์— ์ง„์ž…ํ–ˆ์„ ๋•Œ ํ˜ธ์ถœ์„ ํ•ด์•ผํ•˜๊ณ  ํ˜ธ์ถœํ• ๋•Œ ๊ฐ™์ด ๋˜์ง€๋Š” ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ ์ „์—ญ์œผ๋กœ ์‚ฌ์šฉ์ค‘์ธ ๋‹ค๋ฅธ api์™€ ์˜์กด์„ฑ์ด ์žˆ์—ˆ๊ธฐ ๋•Œ๋ฌธ์—
useEffect / useIonViewWillEnter๊ฐ€ ์•„๋‹Œ useIonViewDidEnter๋กœ ๋ณ€๊ฒฝํ–ˆ๋”๋‹ˆ ํ•ด๊ฒฐ์ด ๋˜์—ˆ๋‹ค

๋˜ํ•œ ionModal์€ ํŽ˜์ด์ง€ ํ˜•ํƒœ๊ฐ€ ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์— ionViewWillEnter, ionViewDidEnter, ionViewWillLeave,ionViewDidLeave์™€ ๊ฐ™์€ 4๊ฐ€์ง€์˜ Ionic Lifecycle์ด ์ •์ƒ์ ์œผ๋กœ ๋™์ž‘ํ•˜์ง€ ์•Š๋Š”๋‹ค๋Š” ์  ๋ช…์‹œํ•ด์•ผ ํ•œ๋‹ค. ์ด๊ฑด ํ•ด๋‹น ํ™”๋ฉด์ด ํŽ˜์ด์ง€์ธ ๊ฒฝ์šฐ์— ์ •์ƒ ๋™์ž‘ํ•œ๋‹ค. (IonPage๋กœ ๊ฐ์‹ธ๊ณ  ์žˆ์œผ๋ฉด ๊ฐ€๋Šฅํ• ์ง€๋„? ํ•˜์ง€๋งŒ ๋ชจ๋‹ฌ์€ ํŽ˜์ด์ง€๊ฐ€ ์•„๋‹ˆ๋‹ˆ๊นŒ...)

๋•Œ๋ฌธ์— ๋ชจ๋‹ฌ์˜ ์ƒ๋ช…์ฃผ๊ธฐ์™€ ๊ด€๋ จ๋œ ๋ฉ”์†Œ๋“œ๋Š” onDidMiss, onWillDismiss ๋“ฑ์„ ์‚ฌ์šฉํ•ด์•ผ ์ •์ƒ์ ์œผ๋กœ ๋™์ž‘ํ•œ๋‹ค (์ฑฐ๊ณ  : https://ionicframework.com/docs/api/modal)

profile
Front-end engineer

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