๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ“‚ ์‚ฝ์งˆ ๋…ธํŠธ/์—๋Ÿฌ ํ•ด๊ฒฐ

<h>์— ๋ฒ„ํŠผ ์†์„ฑ์„ ๋ถ€์—ฌํ•˜๋ฉด ..

by Dev. Ella 2023. 5. 22.

๐Ÿค”  ์˜ค๋Š˜์˜ ์—๋Ÿฌ

React๋กœ ์ฝ”๋“œ๋ฅผ ์งœ๋˜ ์ค‘, ์˜ค๋Š˜์€ ์•„๋ž˜์™€ ๊ฐ™์€ ์ฝ˜์†” ์—๋Ÿฌ๋ฅผ ๋งŒ๋‚ฌ๋‹ค.

 

Received `true` for a non-boolean attribute `button`.
If you want to write it to the DOM, pass a string instead: 
button="true" or button={value.toString()}.

 
 

๐Ÿง ์ฒ˜์Œ ์ž‘์„ฑํ•œ ์ฝ”๋“œ

์ฒ˜์Œ์—๋Š” <h4> ์š”์†Œ์— button ์†์„ฑ์„ ๋ถ€์—ฌํ•ด, ํด๋ฆญํ•˜๋ฉด ๋ชจ๋‹ฌ์ด ๋‚˜ํƒ€๋‚˜๊ณ  ๋‹ค์‹œ ํด๋ฆญํ•˜๋ฉด ๋ชจ๋‹ฌ์ด ์—†์–ด์ง€๋„๋ก ํ–ˆ๋‹ค. ์ด ๋ถ€๋ถ„์ด ๋ฌธ์ œ์˜€๋‹ค.

{
  title.map(function(a, i){ 
    return (
      <div className="list" key={i}> 
      	{/* ์ด ๋ถ€๋ถ„ ์ˆ˜์ • ํ•„์š” */}
        <h4 onClick={() => { setModal(!modal); setModalTitle(i) }}>{ title[i] }
          <span onClick={()=>{
            let copy = [...thumb];
            copy[i] = copy[i] + 1;
            setThumb(copy)
          }}> ๐Ÿ‘ </span>{ thumb[i] }
        </h4>
        <p className="share">๐Ÿ“ฎ ๊ณต์œ ํ•˜๊ธฐ</p>
      </div>
    )
  }) 
}

 
 

๐Ÿ’ก ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

button ์†์„ฑ ์ œ๊ฑฐ, <span>์œผ๋กœ ํด๋ฆญ ์ด๋ฒคํŠธ ์ถ”๊ฐ€

๋””๋ฒ„๊น… ๋ฐ ์„œ์นญ์„ ํ•ด ๋ณด๋‹ˆ, ์œ„ ์—๋Ÿฌ๋Š” JSX ์‚ฌ์šฉ ๋ฐฉ์‹์ด ์ž˜๋ชป๋˜์—ˆ๊ธฐ ๋•Œ๋ฌธ์— ๋ฐœ์ƒํ•œ ๊ฒƒ์ด๋ผ๊ณ  ํ•œ๋‹ค. ํ˜„์žฌ <h4> ์š”์†Œ์— button ์†์„ฑ์ด ๋ถ€์—ฌ๋˜์–ด ์žˆ๋Š”๋ฐ, button์€ ๋ฌธ์ž์—ด ๋˜๋Š” ๋ถˆ๋ฆฌ์–ธ ๊ฐ’๋งŒ ํ—ˆ์šฉ๋œ๋‹ค. ๋”ฐ๋ผ์„œ <h4> ์š”์†Œ์— button ์†์„ฑ์„ ์ œ๊ฑฐํ•˜๊ณ , ๋Œ€์‹  ํด๋ฆญ ์ด๋ฒคํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ์š”์†Œ์ธ <span>์„ ์‚ฌ์šฉํ•˜์—ฌ ํด๋ฆญ ์ด๋ฒคํŠธ๋ฅผ ์ถ”๊ฐ€ํ•˜๋ฉด ํ•ด๊ฒฐ์ด ๋œ๋‹ค.

{
  title.map(function(a, i){ 
    return (
      <div className="list" key={i}> 
        <h4>
          <span onClick={() => { setModal(!modal); setModalTitle(i) }}>{ title[i] }</span>
          <span onClick={()=>{
            let copy = [...thumb];
            copy[i] = copy[i] + 1;
            setThumb(copy)
          }}> ๐Ÿ‘ </span>{ thumb[i] }
        </h4>
        <p className="share">๐Ÿ“ฎ ๊ณต์œ ํ•˜๊ธฐ</p>
      </div>
    )
  }) 
}

 
 

๐Ÿ˜… Today I learned

์‚ฌ์‹ค ๊ธฐ๋Šฅ์ด ์•ˆ ๋Œ์•„๊ฐˆ ์ •๋„์˜ ํฌ๋ฆฌํ‹ฐ์ปฌํ•œ ์—๋Ÿฌ๋Š” ์•„๋‹ˆ์—ˆ์ง€๋งŒ, ๋ฉฐ์น  ์ „ ์ฝ˜์†” ์—๋Ÿฌ๋ฅผ ๊ทธ๋ƒฅ ์ง€๋‚˜์น˜๋ฉด ์•ˆ ๋œ๋‹ค๋Š” ํ”ผ๋“œ๋ฐฑ์„ ๋ฐ›๊ณ  ์ด์ œ ์ฝ˜์†” ์—๋Ÿฌ๋„ ํ•˜๋‚˜ํ•˜๋‚˜ ์‚ดํŽด๋ณด๋ฉด์„œ ์ˆ˜์ •ํ•˜๊ณ  ์žˆ๋‹ค. ๋š๋”ฑ๋š๋”ฑ ๋œฏ์–ด๊ณ ์น˜๋Š” ์žฌ๋ฏธ๊ฐ€ ์žˆ๋‹ค.
 
 

๋Œ“๊ธ€