<div
  dangerouslySetInnerHTML={{
    __html: `
      <img src="http://unsplash.it/100/100?random" onload="console.log('you got hacked');" />
    `,
  }}
/>

가끔 아주 가끔 이상한 일을 해야할때가 있는데 그럴때는 이렇게 하면 된다.

dangerouslySetInnerHTML 은 innerHTML 을 덮어쓰는 것이라1 <script> 는 실행되지 않지만 이벤트 핸들러 속성(onload·onerror)은 실행된다.2


Footnotes

  1. Common components – React: “Overrides the innerHTML property of the DOM node and displays the passed HTML inside.” ↩

  2. Element: innerHTML property - MDN: “While the property does prevent