react-dom#hydrate TypeScript Examples

The following examples show how to use react-dom#hydrate. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.tsx    From react-loosely-lazy with Apache License 2.0 6 votes vote down vote up
renderApp = (v: string) => {
  const appContainer = document.querySelector('#app');
  const mode = isRender() ? MODE.RENDER : MODE.HYDRATE;

  if (v === 'SSR' && appContainer && !isFailSsr()) {
    const components = buildServerComponents(mode);
    const ssr = renderToString(<App initialStep={v} components={components} />);
    appContainer.innerHTML = isRender() ? `<div>${ssr}</div>` : ssr;
  }
  if (v === 'PAINT LOADING') {
    const components = buildClientComponents(mode);
    const renderer = isRender() ? render : hydrate;

    renderer(<App initialStep={v} components={components} />, appContainer);
  }
}
Example #2
Source File: SSR.tsx    From motion with MIT License 6 votes vote down vote up
Demo = () => {
  const ssr = ReactDOMServer.renderToString(
    <MotionAppear supportMotion={false} />,
  );

  React.useEffect(() => {
    const div = document.createElement('div');
    document.body.appendChild(div);
    div.innerHTML = ssr;

    hydrate(<MotionAppear supportMotion />, div);

    return () => {
      document.body.removeChild(div);
    };
  }, []);

  return (
    <div>
      <textarea value={ssr} style={{ width: '100%' }} rows={5} readOnly />
    </div>
  );
}
Example #3
Source File: index.tsx    From react-app-architecture with Apache License 2.0 5 votes vote down vote up
hydrate(<Routes />, document.getElementById('root'));
Example #4
Source File: entry.client.tsx    From remix-hexagonal-architecture with MIT License 5 votes vote down vote up
hydrate(<RemixBrowser />, document);
Example #5
Source File: entry.client.tsx    From tweet2image with MIT License 5 votes vote down vote up
hydrate(<RemixBrowser />, document)
Example #6
Source File: entry.client.tsx    From geist-ui with MIT License 5 votes vote down vote up
hydrate(<RemixBrowser />, document)