๊ด€๋ฆฌ ๋ฉ”๋‰ด

๋ชฉ๋ก๋™์ผ ํŒŒ์ผ ์—…๋กœ๋“œ (1)

Hey Tech

[React] Input Tag์—์„œ ๊ฐ™์€ ํŒŒ์ผ ์—…๋กœ๋“œํ•˜๋Š” ๋ฐฉ๋ฒ•

๐Ÿ“š ๋ชฉ์ฐจ 1. AS IS: ๋™์ผ ํŒŒ์ผ ์—…๋กœ๋“œ ๋ถˆ๊ฐ€ํ•œ ๊ฒฝ์šฐ 2. ํ•ด๊ฒฐ๋ฐฉ๋ฒ• 3. TO BE: ๋™์ผ ํŒŒ์ผ ์—…๋กœ๋“œ ๊ฐ€๋Šฅํ•œ ๊ฒฝ์šฐ 1. AS IS: ๋™์ผ ํŒŒ์ผ ์—…๋กœ๋“œ ๋ถˆ๊ฐ€ํ•œ ๊ฒฝ์šฐ ์•„๋ž˜์˜ ์˜ˆ์‹œ๋กœ ์ƒํ™ฉ์„ ์„ค๋ช…ํ•ด ๋“œ๋ฆฝ๋‹ˆ๋‹ค(๊ทธ๋ฆผ 1). ํŒŒ์ผ ์—…๋กœ๋“œ ์‹œ(i.e., onChange) ํŒ์—…์ด ๋œจ๋Š” ๋กœ์ง์„ ์ž‘์„ฑํ•˜์˜€์Šต๋‹ˆ๋‹ค. ํ—Œ๋ฐ, ๊ฐ™์€ ํŒŒ์ผ์„ ์—…๋กœ๋“œํ•  ๊ฒฝ์šฐ ์ดํ›„ ๋กœ์ง์ด ์ˆ˜ํ–‰๋˜์ง€ ์•Š๋Š” ๊ฒƒ์„ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. 2. ํ•ด๊ฒฐ๋ฐฉ๋ฒ• { this.onFileChange(e); e.target.value = ''; }}/> input ํƒœ๊ทธ์—์„œ onChange ์˜ต์…˜์—์„œ ํŒŒ์ผ ์—…๋กœ๋“œ ๋กœ์ง ํ˜ธ์ถœ ํ›„ event์—์„œ value๋ฅผ ์ดˆ๊ธฐํ™”ํ•˜๋ฉด ํ•ด๊ฒฐ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. 3. TO BE: ๋™์ผ ํŒŒ์ผ ์—…๋กœ๋“œ ๊ฐ€๋Šฅํ•œ ๊ฒฝ์šฐ ์ฝ”๋“œ๋ฅผ ์ ์šฉํ•˜๋ฉด ์œ„์˜ ๊ทธ๋ฆผ 2์™€ ๊ฐ™์ด ๊ฐ™์€ ํŒŒ..

SW ๊ฐœ๋ฐœ/React JS 2022. 7. 20. 08:32