/plugin-initial-state

Umi plugin to store initial state globally.

Primary LanguageTypeScript

English | 中文文档

@umijs/plugin-initial-state

codecov NPM version CircleCI GitHub Actions status NPM downloads

Umi plugin to store initial state globally.

Install

# or yarn
$ npm install @umijs/plugin-initial-state --save

Usage

Getting started in 3 steps.

1. Configure in .umirc.js

export default {
  plugins: [['@umijs/plugin-initial-state', options]],
};

2. Add getInitialState into src/app.ts

export async function getInitialState() {
  return 'Hello World';
}

3. Use it in your React Component or other models

import React from 'react';
import { useModel } from 'umi';

export default () => {
  const { initialState, loading, refresh } = useModel('@@initialState');
  return <>{ loading ? 'loading...' : initialState }</>;
};

Full example can find in ./example.

LICENSE

MIT