Download next.js/test/integration/app-tree/pages/hello.tsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 838 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/test/integration/app-tree/pages/hello.tsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/test/integration/app-tree/pages/hello.tsx
-
curl -L -o hello.tsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/test/integration/app-tree/pages/hello.tsx
838 Bytes
| import React from 'react' | |
| import { flushSync } from 'react-dom' | |
| import { createRoot } from 'react-dom/client' | |
| import { renderToString } from 'react-dom/server' | |
| import { NextPage } from 'next' | |
| const Page: NextPage<{ html: string }> = ({ html }) => | |
| html ? ( | |
| <> | |
| <p>saved:</p> | |
| <div dangerouslySetInnerHTML={{ __html: html }} /> | |
| </> | |
| ) : ( | |
| <p>Hello world</p> | |
| ) | |
| Page.getInitialProps = async ({ AppTree }) => { | |
| let html: string | |
| const toRender = <AppTree pageProps={{}} /> | |
| if (typeof window !== 'undefined') { | |
| const el = document.createElement('div') | |
| document.querySelector('body')?.appendChild(el) | |
| flushSync(() => { | |
| createRoot(el).render(toRender) | |
| }) | |
| html = el.innerHTML | |
| el.remove() | |
| } else { | |
| html = renderToString(toRender) | |
| } | |
| return { html } | |
| } | |
| export default Page | |