Build React's renderToStaticMarkup: escaping, attribute and style rules, void elements, components and context

hardAbout 60 minutesUpdated CodingProreactssrserver-renderingreact-elementsinternalssecurity
Not solved

Share this question

Problem

renderToStaticMarkup turns a React element tree into an HTML string with nothing extra for hydration: email templates, static pages, RSS, the HTML of a PDF. Writing it yourself forces you to know what a React element really is, how components are called, and the small rules React applies to every prop. Those rules are also where XSS bugs live. Build it, and match React's output exactly: the tests compare your string with react-dom/server.

renderToStaticMarkup(<label className="field" htmlFor="email" onClick={save} style={{ fontSize: 12 }}>Email</label>);
// '<label class="field" for="email" style="font-size:12px">Email</label>'

Ref. UR-1440 · © UIRound · uiround.com/questions/build-reacts-rendertostaticmarkup-escaping-attribute-and-style-rules-void-elements-components-and-context

Stuck? Take a hint

Try it in the editor

Run your code as often as you like. Submitting it to the full test suite is part of Pro.

Private, and saved in this browser as you type. All your notes are on My lists.

Every question and answer7 days, one payment