當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript react-intl.defineMessages函數代碼示例

本文整理匯總了TypeScript中react-intl.defineMessages函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript defineMessages函數的具體用法?TypeScript defineMessages怎麽用?TypeScript defineMessages使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了defineMessages函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: defineMessages

/* eslint-env browser */
import { defineMessages } from 'react-intl';
import { useAppContext } from './useAppContext';

const messages = defineMessages({
  areYouSure: {
    defaultMessage: 'Are you sure?',
    id: 'confirm.areYouSure',
  },
});

export const useConfirm = () => {
  const { intl } = useAppContext();

  const confirm = () => {
    // eslint-disable-next-line no-alert
    return window.confirm(intl.formatMessage(messages.areYouSure));
  };

  return confirm;
};
開發者ID:este,項目名稱:este,代碼行數:21,代碼來源:useConfirm.ts

示例2: defineMessages

import { handleApiGraphQLError } from '@app/api/handleApiGraphQLError';
import Router from 'next/router';
import { useState, useRef, useEffect, useMemo } from 'react';
import { defineMessages } from 'react-intl';
import { commitMutation, GraphQLTaggedNode } from 'react-relay';
import { Disposable } from 'relay-runtime';
import { useAppHref } from './useAppHref';
import { useAppContext } from './useAppContext';

const messages = defineMessages({
  forbidden: {
    defaultMessage: 'This action is forbidden.',
    id: 'useMutation.forbidden',
  },
  noInternetAccess: {
    defaultMessage: 'Please check your internet connection.',
    id: 'useMutation.noInternetAccess',
  },
  notFound: {
    defaultMessage: 'Not found.',
    id: 'useMutation.notFound',
  },
});

// While it's possible to have multiple fields (mutations) in one mutation,
// I don't think it's a good pattern for client usage. There are questions
// related to transactions, race conditions, and batching. I believe server
// API should provide well tailored mutation for such use case.
// Therefore, this Hook supports only the one mutation with the one input.
// https://graphql.org/learn/queries/#multiple-fields-in-mutations

interface Focusable {
開發者ID:este,項目名稱:este,代碼行數:32,代碼來源:useMutation.ts

示例3: defineMessages

/*
 * Vmform Messages
 *
 * This contains all the text for the Vmform component.
 */
import { defineMessages } from 'react-intl';

export default defineMessages({
  infrastructure: {
    id: 'app.components.Vmform.infrastructure',
    defaultMessage: 'Infrastructure settings',
  },
  account: {
    id: 'app.components.Vmform.account',
    defaultMessage: 'Account settings',
  },
  resources: {
    id: 'app.components.Vmform.resources',
    defaultMessage: 'Resources settings',
  },
  hooks: {
    id: 'app.components.Vmform.hooks',
    defaultMessage: 'Post-creation hooks settings',
  },
  network: {
    id: 'app.components.Vmform.network',
    defaultMessage: 'Network connection settings'
  }
});
開發者ID:,項目名稱:,代碼行數:29,代碼來源:

示例4: defineMessages

import { defineMessages } from 'react-intl';
import { useMemo } from 'react';
import { useAppContext } from './useAppContext';

export const pageTitles = defineMessages({
  index: {
    defaultMessage: 'Este',
    id: 'pageTitles.index',
  },
  me: {
    defaultMessage: 'Me',
    id: 'pageTitles.me',
  },
  signIn: {
    defaultMessage: 'Sign in',
    id: 'pageTitles.signIn',
  },
});

// Page titles can not be collocated within pages because that would defeat
// code splitting. One nav component would import many pages.
export const usePageTitles = () => {
  const { intl } = useAppContext();
  const titles = useMemo(() => {
    return {
      // Note we can add function for formatMessage values.
      index: intl.formatMessage(pageTitles.index),
      me: intl.formatMessage(pageTitles.me),
      signIn: intl.formatMessage(pageTitles.signIn),
    };
  }, [intl]);
開發者ID:este,項目名稱:este,代碼行數:31,代碼來源:usePageTitles.ts


注:本文中的react-intl.defineMessages函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。