๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

TIL/ETC

React ๋ฌธ์ž์—ด ํ˜•ํƒœ์˜ htmlํƒœ๊ทธ ๋ Œ๋”๋ง ํ•˜๊ธฐ

React๋ฅผ ์‚ฌ์šฉํ•˜๋‹ค๊ฐ€ html ํƒœ๊ทธ๋ฅผ ๋ฆฌํ„ดํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ๊ตฌํ˜„ํ–ˆ๋Š”๋ฐ ๊ทธ ํƒœ๊ทธ๋“ค์ด ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅ๋˜๋Š” ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ–ˆ๋‹ค.

์ˆ˜์ • ์ „

์ด๋ฅผ ๋ณธ๋ž˜ ์˜๋„๋Œ€๋กœ htmlํƒœ๊ทธ ์—ญํ• ์„ ํ•˜๋„๋ก ํ•˜๋ ค๋ฉด python์—์„œ datatype์„ ๋ณ€๊ฒฝํ•ด์ฃผ๋“ฏ์ด

๋ฌธ์ž์—ด -> html ๋กœ ์ธ์‹ํ•˜๋„๋ก ๋ณ€๊ฒฝํ•ด์ค˜์•ผํ•œ๋‹ค.

 

import React from 'react';

const Test = () => {
  let codes = '<b>Hello world</b>';
  return <div dangerouslySetInnerHTML={{ __html: codes }}></div>;
}

export default Test;

 

์ˆ˜์ • ํ›„

์ž˜ ์ถœ๋ ฅ๋˜๋Š” ๊ฒƒ์„ ํ™•์ธ