• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript react-intl.defineMessages函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript react-is.isElement函数代码示例发布时间:2022-05-25
下一篇:
TypeScript react-hooks-testing-library.renderHook函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap