How to use the umi.useModel function in umi

To help you get started, we’ve selected a few umi 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 apache / apisix-dashboard / web / src / components / RightContent / AvatarDropdown.tsx View on Github external
const AvatarDropdown: React.FC = ({ menu }) => {
  const { formatMessage } = useIntl();
  const { initialState, setInitialState } = useModel('@@initialState');

  const onMenuClick = useCallback((event) => {
    const { key } = event;
    if (key === 'settings') {
      settings();
      return;
    }

    if (key === 'logout') {
      setInitialState({ ...initialState, currentUser: undefined });
      history.replace({
        pathname: '/user/logout',
        search: stringify({
          redirect: window.location.pathname,
        }),
      });
github oam-dev / kubevela / references / dashboard / src / pages / Capability / Workloads / index.tsx View on Github external
export default (): React.ReactNode => {
  const { loading, workloadList } = useModel('useWorkloadsModel');

  const [showWorkload, setShowWorkload] = useState(DEFAULT_DETAIL_STATE);

  const showInfo = ({ parameters }: { parameters: ShowParameters }) => {
    setShowWorkload(parameters);
  };

  return (
    
      
      
        
          rowKey="name"
          headerTitle="Type"
          loading={loading ? { delay: 300 } : undefined}
          dataSource={workloadList ?? []}
github umijs / plugin-model / example / pages / index.tsx View on Github external
export default () => {
  const fullRet = useModel('counter');
  const partialRet = useModel('counter', c => c.counter);

  return (<>
    {partialRet}
    <button>add</button>
    <button>minus</button>
  );
}
github oam-dev / kubevela / references / dashboard / src / components / RightContent / index.tsx View on Github external
const GlobalHeaderRight: React.FC&lt;{}&gt; = () =&gt; {
  const { initialState } = useModel('@@initialState');

  if (!initialState || !initialState.settings) {
    return null;
  }

  const { navTheme, layout } = initialState.settings;
  let className = styles.right;

  if ((navTheme === 'dark' &amp;&amp; layout === 'top') || layout === 'mix') {
    className = `${styles.right}  ${styles.dark}`;
  }
  return (
    
      {REACT_APP_ENV &amp;&amp; (
        <span>
          {REACT_APP_ENV}</span>
github apache / apisix-dashboard / web / src / components / RightContent / index.tsx View on Github external
const GlobalHeaderRight: React.FC = () => {
  const { initialState } = useModel('@@initialState');

  useEffect(() => {
    if (localStorage.getItem('token')) {
      fetchVersionMatch();
    }
  }, []);

  if (!initialState || !initialState.settings) {
    return null;
  }

  const { navTheme, layout } = initialState.settings;
  let className = styles.right;

  if ((navTheme === 'dark' && layout === 'top') || layout === 'mix') {
    className = `${styles.right}  ${styles.dark}`;
github sorrycc / learn-react-with-umi / plugin-model / pages / index.tsx View on Github external
export default function() {
  const [value, setValue] = useState('');
  const { todos, addTodo, fetchTodos } = useModel('todos');
  const { count } = useModel('count');
  const { initialState } = useModel('@@initialState');
  return (
    <div>
      <h1>Page index</h1>
      <h2>Test {initialState || ''}</h2>
      <h2>Todos ({count})</h2>
      {
        todos.map(({ name, done }) =&gt; {
          return <li>{ name }</li>;
        })
      }
      <form> {
        ev.preventDefault();
        await addTodo(value);
        setValue('');
        await fetchTodos();
      }}&gt;</form></div>
github oam-dev / kubevela / references / dashboard / src / pages / Capability / Traits / index.tsx View on Github external
export default (): React.ReactNode =&gt; {
  const { loading, traitsList } = useModel('useTraitsModel');

  const [showTraits, setShowTraits] = useState(DEFAULT_DETAIL_STATE);

  const showInfo = ({ traits }: { traits: ShowParameters }) =&gt; {
    setShowTraits({ ...traits });
  };

  return (
    
      
      
        
          rowKey="name"
          headerTitle="Type"
          pagination={{
            defaultPageSize: 5,
github oam-dev / kubevela / references / dashboard / src / pages / Application / Create / components / CapabilitySelector / index.tsx View on Github external
const CapabilitySelector: React.FC = ({
  capability,
  onSelect,
  disableCapabilities,
}) =&gt; {
  const workloadModel = useModel('useWorkloadsModel');
  const traitModel = useModel('useTraitsModel');

  let loading: boolean | undefined;
  let data: { name: string; description?: string }[] | null;

  switch (capability) {
    case 'service':
      loading = workloadModel.loading;
      data = workloadModel.workloadList ?? null;
      break;
    case 'trait':
      loading = traitModel.loading;
      data = traitModel.traitsList ?? null;
      break;
    default:
      throw new Error(`invalid capability: '${capability}'.`);
  }
github sorrycc / learn-react-with-umi / plugin-model / pages / index.tsx View on Github external
export default function() {
  const [value, setValue] = useState('');
  const { todos, addTodo, fetchTodos } = useModel('todos');
  const { count } = useModel('count');
  const { initialState } = useModel('@@initialState');
  return (
    <div>
      <h1>Page index</h1>
      <h2>Test {initialState || ''}</h2>
      <h2>Todos ({count})</h2>
      {
        todos.map(({ name, done }) =&gt; {
          return <li>{ name }</li>;
        })
      }
      <form> {
        ev.preventDefault();
        await addTodo(value);
        setValue('');</form></div>
github oam-dev / kubevela / references / dashboard / src / components / RightContent / WorkSpaceDropDown.tsx View on Github external
export default () =&gt; {
  const {
    environments,
    currentEnvironment,
    switchCurrentEnvironment: switchEnvironment,
  } = useModel('useEnvironmentModel');

  const menu = (
    <menu> {
        switchEnvironment(e.key.toString()).then((env) =&gt; {
          if (env == null) {
            return;
          }
          message.success({
            content: `Set environment succeed, current environment is ${env.envName}, namespace is ${env.namespace}`,
            key: 'switchEnvironment',
          });
        });
      }}</menu>