How to use the mobx-react-lite.useStaticRendering function in mobx-react-lite

To help you get started, we’ve selected a few mobx-react-lite 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 zeit / next.js / examples / with-mobx-react-lite / store.js View on Github external
import { action } from 'mobx'
import { useObservable, useStaticRendering } from 'mobx-react-lite'
import { createContext, useCallback } from 'react'

const isServer = typeof window === 'undefined'
// eslint-disable-next-line react-hooks/rules-of-hooks
useStaticRendering(isServer)

let StoreContext = createContext()
let start
let stop
let store

function initializeData(initialData = store || {}) {
  const { lastUpdate = Date.now(), light } = initialData
  return {
    lastUpdate,
    light: Boolean(light),
  }
}

function InjectStoreContext({ children, initialData }) {
  let timerInterval = null
github leebenson / reactql / src / entry / server.tsx View on Github external
// Class for handling Webpack stats output
import Output from "@/lib/output";

// Every byte sent back to the client is React; this is our main template
import Html from "@/views/ssr";

// ----------------------------------------------------------------------------

// Types
export interface IRouterContext {
  status?: number;
  url?: string;
}

// Enable SSR-mode with MobX to avoid memory leaks
useStaticRendering(true);

// Everything from this point will be Webpack'd and dumped in `dist/server.js`
// and then loaded into an active Koa server
export default function(output: Output) {
  // Create Koa middleware to handle React requests
  return async (ctx: Context) => {
    // Create a new Apollo client
    const client = createClient();

    // Create a fresh 'context' for React Router
    const routerContext: IRouterContext = {};

    // Render our components - passing down MobX state, a GraphQL client,
    // and a router for rendering based on our route config
    const components = (
github tonyfromundefined / next-starter / src / services / index / store / index.ts View on Github external
import { Request, Response } from 'express-serve-static-core'
import { useStaticRendering } from 'mobx-react-lite'
import { types } from 'mobx-state-tree'
import { createContext, useContext } from 'react'
import { checkTokenIsExpired, removeMapInCookie, setMapInCookie } from '../helpers'

const isServer = typeof window === 'undefined'

useStaticRendering(isServer)

export interface IEnvironments {
  [key: string]: string
}
export interface ITokens {
  accessToken: string
  refreshToken: string
}

export type IStore = typeof Store.Type
type IStoreState = typeof Store.CreationType

let store: IStore | null = null

export function createStore(storeState: IStoreState): IStore {
  if (isServer) {