Skip to content

Instantly share code, notes, and snippets.

@onosendi
Last active March 8, 2022 14:33
Show Gist options
  • Save onosendi/64f52fc70943dfdea336e01d0b4d4765 to your computer and use it in GitHub Desktop.
Save onosendi/64f52fc70943dfdea336e01d0b4d4765 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Foo</title>
</head>
<body>
<div id="root" data-foo="{&quot;foo&quot;: &quot;bar&quot;}"></div>
</body>
</html>
import React from 'react';
import ReactDOM from 'react-dom';
const rootEl = document.getElementById('root');
let foo;
try {
foo = JSON.parse(rootEl.dataset.foo);
} catch (error) {
console.error(error);
}
function App({ foo }) {
console.log(foo);
return null;
}
ReactDOM.render(<App foo={foo} />, rootEl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment