React JSX ๐Ÿ™„๐Ÿ™„

c_yjยท2022๋…„ 7์›” 17์ผ
0

React

๋ชฉ๋ก ๋ณด๊ธฐ
8/13
post-thumbnail

JSX๋ž€ โ“

Javascript์— XML์„ ์ถ”๊ฐ€ํ•œ ํ™•์žฅํ•œ ๋ฌธ๋ฒ•์ด๋‹ค
JSX๋กœ ์ž‘์„ฑํ•œ ์ฝ”๋“œ๋Š” ๋ธŒ๋ผ์šฐ์ €์—์„œ ์‹คํ–‰ํ•˜๊ธฐ ์ „์— ๋ฐ”๋ฒจ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ผ๋ฐ˜ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ํ˜•ํƒœ์˜ ์ฝ”๋“œ๋กœ ๋ณ€ํ™˜๋œ๋‹ค.
JSX ๊ณต์‹์ ์ธ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ๋ฌธ๋ฒ•์€ ์•„๋‹ˆ๋‹ค.

JSX ๊ทœ์น™ ๐ŸŸ 

1. ๋ฐ˜๋“œ์‹œ ๋ถ€๋ชจ์š”์†Œ๋กœ ๊ฐ์‹ธ์•ผ ํ•œ๋‹ค.

const App = () => {
  return(
    <div>
    	<h1>๋ฐ˜๋“œ์‹œ ๋ถ€๋ชจ์š”์†Œ๋กœ ๊ฐ์‹ธ์•ผ ํ•œ๋‹ค</h1>
    </div>
   )

2. ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ํ‘œํ˜„์‹

JSX ์•ˆ์—์„œ {}๋กœ ๊ฐ์‹ธ๋ฉด ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค

const App = () => {
  const title = '๋ฐ˜๋“œ์‹œ ๋ถ€๋ชจ์š”์†Œ๋กœ ๊ฐ์‹ธ์•ผ ํ•œ๋‹ค';
  return(
    <div>
    	<h1>{title}</h1>
    </div>
   )

3. ์กฐ๊ฑด๋ถ€ ์—ฐ์‚ฐ์ž

JSX ๋‚ด๋ถ€์—์„œ๋Š” if๋ฌธ๊ณผ for๋ฌธ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋‹ค. ๊ทธ๋ ‡๊ธฐ ๋–„๋ฌธ์— JSX๋ฐ–์—์„œ if๋ฌธ๊ณผ for๋ฌธ ๋“ฑ์„ ์ž‘์„ฑํ•˜๊ฑฐ๋‚˜, ์‚ผํ•ญ์—ฐ์‚ฐ์ž(์กฐ๊ฑด๋ถ€ ์—ฐ์‚ฐ์ž)๋ฅผ ์‚ฌ์šฉํ•˜์ž

const App = () => {
  const title = 'h1';
  return(
    <div>
    	{title === 'h1' ? <h1>์‚ผํ•ญ์—ฐ์‚ฐ์ž</h1> : <h1>Title</h1>}
    </div>
   )

https://ko.reactjs.org/docs/introducing-jsx.html
https://goddaehee.tistory.com/296

profile
FrontEnd Developer

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