rsnext/examples/with-noscript/components/Noscript.js
Henrik Wenz 02e75cfdd1 Simplify with-noscript example (#9094)
## Changelog

- Removed react-lazyload
- Removed images
- Removed ReactDOMServer from Client
- Removed next.config.js

## Notes

**CommonJS vs ESM:** In the future we might be able to use top level `await` in order to import only on the server (e.g.: `await import(“react-dom/server”)`)

Until then we need to mix CommonJS and ESM in favor of messing with the webpack config.
2019-10-16 12:36:40 +02:00

15 lines
430 B
JavaScript

import React from 'react'
// We don't want to send 'react-dom/server' to the client
let ReactDOMServer
if (typeof window === 'undefined') {
ReactDOMServer = require('react-dom/server')
}
export default function Noscript ({ children }) {
if (!ReactDOMServer) {
return null
}
const staticMarkup = ReactDOMServer.renderToStaticMarkup(children)
return <noscript dangerouslySetInnerHTML={{ __html: staticMarkup }} />
}