当前位置: 首页>>代码示例>>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;未经允许,请勿转载。