How to use the next/dynamic function in next

To help you get started, we’ve selected a few next examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github devinit / datahub / packages / app / src / components / templates / CountryProfile / index.tsx View on Github external
import Router from 'next/router';
import Link from 'next/link';
import Generic from '../Generic';

// TODO: the dynamic types are a pain to work with, need to get improved submit PR
const dynamicOpts: DynamicOptions = {
  ssr: true,
  loading: () =&gt; <p>Loading...</p>,
    modules: props =&gt; ({
        CountryProfileLowerTabs: import('../../organisms/CountryProfileLowerTabs') as Promise
      }),
    render: (props, {CountryProfileLowerTabs}) =&gt;
        
};

const DynamicCountryProfileLowerTabs = dynamic(dynamicOpts as any);

interface Props  {
  id: string;
  rehydrated?: boolean;
  state?: StateToShare;
}

export default class Profile extends React.Component {
  public static init(props) {
    const country = getCountry(props.id);
    const selectedTab = props.state &amp;&amp; props.state.chartId &amp;&amp;
      props.state.chartId !== GOVERNMENT_FINANCE_LOWER ? 1 : 0;
    return {selectedTab, country};
  }
  public state: {
    selectedTab: number,
github conveyal / taui / src / components / application.js View on Github external
import RouteCard from './route-card'
import RouteSegments from './route-segments'
import TimeCutoff from './time-cutoff'

const Loader = () =&gt; (
  <div>
    
  </div>
)

// Certain components depend on config options, so dynamically load them
const ConfigCard = dynamic(() =&gt; import('./config-card'))
const Log = dynamic(() =&gt; import('./log'))
const GeocodeSearch = dynamic(() =&gt; import('./geocode-search'), {ssr: false})
const Info = dynamic(() =&gt; import('./info'))
const PoiSearch = dynamic(() =&gt; import('./poi-search'))

// Cannot import map on the server
const Map = dynamic(() =&gt; import('./map'), {
  loading: Loader,
  ssr: false
})

// Default access token
const MBAT = process.env.MAPBOX_ACCESS_TOKEN

export default class Application extends Component {
  state = {
    showInfo: this.props.info &amp;&amp; !this.props.user // first visit to the site
  }

  _geocode = text =&gt; {
github chibicode / Y-Combinator-for-Non-programmers / src / lib / contentBundles.tsx View on Github external
() =&gt; import(/* webpackChunkName: 'yc/2.en' */ 'src/contents/yc/2.en'),
      { loading: () =&gt;  }
    ),
    jp: dynamic(
      // @ts-ignore - import isn't typed correctly
      () =&gt; import(/* webpackChunkName: 'yc/2.jp' */ 'src/contents/yc/2.jp'),
      { loading: () =&gt;  }
    )
  },
  'yc/3': {
    en: dynamic(
      // @ts-ignore - import isn't typed correctly
      () =&gt; import(/* webpackChunkName: 'yc/3.en' */ 'src/contents/yc/3.en'),
      { loading: () =&gt;  }
    ),
    jp: dynamic(
      // @ts-ignore - import isn't typed correctly
      () =&gt; import(/* webpackChunkName: 'yc/3.jp' */ 'src/contents/yc/3.jp'),
      { loading: () =&gt;  }
    )
  },
  'yc/4': {
    en: dynamic(
      // @ts-ignore - import isn't typed correctly
      () =&gt; import(/* webpackChunkName: 'yc/4.en' */ 'src/contents/yc/4.en'),
      { loading: () =&gt;  }
    ),
    jp: dynamic(
      // @ts-ignore - import isn't typed correctly
      () =&gt; import(/* webpackChunkName: 'yc/4.jp' */ 'src/contents/yc/4.jp'),
      { loading: () =&gt;  }
    )
github opencollective / opencollective-frontend / components / collective-page / hero / HeroAvatar.js View on Github external
import Avatar from '../../Avatar';
import LoadingPlaceholder from '../../LoadingPlaceholder';
import StyledRoundButton from '../../StyledRoundButton';
import StyledButton from '../../StyledButton';
import Container from '../../Container';
import { EditAvatarMutation } from '../graphql/mutations';
import Link from '../../Link';

const AVATAR_SIZE = 128;

// Dynamically import components for admins
const DropzoneLoadingPlaceholder = () =&gt; (
  
);
const dynamicParams = { loading: DropzoneLoadingPlaceholder, ssr: false };
const Dropzone = dynamic(() =&gt; import(/* webpackChunkName: 'react-dropzone' */ 'react-dropzone'), dynamicParams);

const EditOverlay = styled.div`
  position: absolute;
  width: 128px;
  height: 128px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: rgba(255, 255, 255, 0.75);
  cursor: pointer;
  text-align: center;
  padding: 1em;
  border-radius: ${props =&gt; props.borderRadius};
`;
github coderplanets / coderplanets_web / pages / editor.js View on Github external
import React from 'react'
import dynamic from 'next/dynamic'
import { Provider } from 'mobx-react'

import initRootStore from '@stores/init'
import ThemeWrapper from '@containers/ThemeWrapper'
// import EditorJS from '@editorjs/editorjs'

// eslint-disable-next-line no-unused-vars
const html =
  '<div class="cps-viewer"><h2 class="cps-viewer-header">Editor.js</h2><p class="cps-viewer-paragraph">Hey. Meet the new Editor. On this page you can see it in action — try to edit this text.</p><h3 class="cps-viewer-header">Key features</h3><ul><li>It is a block-styled editor</li><li>It returns clean data output in JSON</li><li>Designed to be extendable and pluggable with a simple API</li></ul><h3 class="cps-viewer-header">Key features</h3><ol><li>It is a block-styled editor</li><li>It returns clean data output in JSON</li><li>Designed to be extendable and pluggable with a simple API</li></ol><h3 class="cps-viewer-header">What does it mean «block-styled editor»</h3><div class="cps-viewer-checklist"><div>This is a block-styled editor</div><div>Clean output data</div><div>Simple and powerful API</div></div><p class="cps-viewer-paragraph">Workspace in classic editors is made of a single contenteditable element, used to create different HTML markups. Editor.js <mark class="cdx-marker">workspace consists of separate Blocks: paragraphs, headings, images, lists, quotes, etc</mark>. Each of them is an independent contenteditable element (or more complex structure) provided by Plugin and united by Editor\'s Core.</p><p class="cps-viewer-paragraph">There are dozens of <a href="https://github.com/editor-js">ready-to-use Blocks</a> and the <a href="https://editorjs.io/creating-a-block-tool">simple API</a> for creation any Block you need. For example, you can implement Blocks for Tweets, Instagram posts, surveys and polls, CTA-buttons and even games.</p><h3 class="cps-viewer-header">What does it mean clean data output</h3><p class="cps-viewer-paragraph">Classic WYSIWYG-editors produce raw HTML-markup with both content data and content appearance. On the contrary, Editor.js outputs JSON object with data of each Block. You can see an example below</p><p class="cps-viewer-paragraph">Given data can be used as you want: render with HTML for <code class="inline-code">Web clients</code>, render natively for <code class="inline-code">mobile apps</code>, create markup for <code class="inline-code">Facebook Instant Articles</code> or <code class="inline-code">Google AMP</code>, generate an <code class="inline-code">audio version</code> and so on.</p><p class="cps-viewer-paragraph">Clean data is useful to sanitize, validate and process on the backend.</p><div class="cps-viewer-delimiter"></div><p class="cps-viewer-paragraph">We have been working on this project more than three years. Several large media projects help us to test and debug the Editor, to make it\'s core more stable. At the same time we significantly improved the API. Now, it can be used to create any plugin for any task. Hope you enjoy. 😏</p><div class="cps-viewer-image"><img src="https://codex.so/upload/redactor_images/o_e48549d1855c7fc1807308dd14990126.jpg"></div><div class="cps-viewer-linker"><a href="https://www.github.com">https://www.github.com</a></div><div class="cps-viewer-quote">quote demo text</div><div>'

export const DynamicRichEditor = dynamic({
  loader: () =&gt; import('@containers/RichEditor'),
  ssr: false,
})

const Editor = () =&gt; {
  const store = initRootStore({ langSetup: {} })

  return (
    
      
        </div></div>
github TallerWebSolutions / next-on-drupal / src / client / modules / drupal / modules / pages / lib / pages.js View on Github external
/**
 * Drupal pages resolution library.
 */

import dynamic from 'next/dynamic'
import ErrorPage404 from '~client/components/ErrorPage404'
import { routes } from './routes'

const NodeArticle = dynamic(() => import('~client/pages/drupal/node/article'))
const NodePage = dynamic(() => import('~client/pages/drupal/node/page'))

// prettier-ignore
// the pages registry, in order of precendence.
const pages = [
  { component: NodeArticle, is: routes['drupal/node/article'] },
  { component: NodePage, is: routes['drupal/node/page'] },
  { component: ErrorPage404, is: () => true }
]

export default pages
github conveyal / taui / src / components / application.js View on Github external
const Loader = () =&gt; (
  <div>
    
  </div>
)

// Certain components depend on config options, so dynamically load them
const ConfigCard = dynamic(() =&gt; import('./config-card'))
const Log = dynamic(() =&gt; import('./log'))
const GeocodeSearch = dynamic(() =&gt; import('./geocode-search'), {ssr: false})
const Info = dynamic(() =&gt; import('./info'))
const PoiSearch = dynamic(() =&gt; import('./poi-search'))

// Cannot import map on the server
const Map = dynamic(() =&gt; import('./map'), {
  loading: Loader,
  ssr: false
})

// Default access token
const MBAT = process.env.MAPBOX_ACCESS_TOKEN

export default class Application extends Component {
  state = {
    showInfo: this.props.info &amp;&amp; !this.props.user // first visit to the site
  }

  _geocode = text =&gt; {
    const p = this.props
    return geocode(text, p.map.accessToken || MBAT, p.geocoder)
  }
github SolidZORO / leaa / packages / leaa-www / src / pages / article / [slug].tsx View on Github external
import React from 'react';
import dynamic from 'next/dynamic';
import { GraphQLError } from 'graphql';

import { Article } from '@leaa/common/src/entrys';
import { GET_ARTICLE_BY_SLUG } from '@leaa/common/src/graphqls';

import { IPageProps, IGetInitialProps } from '@leaa/www/src/interfaces';
import { HtmlMeta, PageCard } from '@leaa/www/src/components';
import { apolloClient } from '@leaa/www/src/libs';
import { messageUtil } from '@leaa/www/src/utils';

const ArticleItem = dynamic(() =&gt; import('./_components/ArticleItem/ArticleItem'));

interface IProps extends IPageProps {
  pageProps: {
    article?: Article;
    articleError?: GraphQLError;
  };
}

const nextPage = (ctx: IProps) =&gt; {
  const { article, articleError } = ctx.pageProps;

  if (articleError) messageUtil.gqlError(articleError?.message);
  if (!article) return null;

  return (
github dappforce / dappforce-subsocial-ui / src / pages / edit-profile.tsx View on Github external
import React from 'react';
import dynamic from 'next/dynamic';
const EditProfile = dynamic(() =&gt; import('../components/profiles/EditProfile').then((mod: any) =&gt; mod.EditProfile), { ssr: false });

import Page from '../layout/Page';

export default () =&gt; ;