reactjs - 如果仅在 Next.js SSG 中的服务器中使用,为什么将时刻 / i18 代码下载到客户端
问题描述
我们使用 moment 和 i18 进行翻译,但仅在服务器端。生成 HTML 时。为什么要下载到客户端?为什么它使用brandwith并增加“互动时间”?
一些代码
import { useEffect, useState } from "react";
import dynamic from "next/dynamic";
import {
getDateString,
getFormattedTimeInterval,
countTotalBookings,
} from "../../Utility/Utility";
import { MainTableProps, EventTypeEnum, PricingOptionType } from "../../Types";
import { useTranslation } from "react-i18next";
import useWindowSize from "../../Utility/UseWindowSize";
import i18n from "i18next";
import accounting from "accounting-js";
import moment from "moment";
function MainTable(props: MainTableProps) {
const {
showOnlyStartEndTime,
eventTimes,
passes,
pricingOptions,
ratingAvg,
minParticipants,
maxParticipants,
} = props.buyTicketData;
const { t } = useTranslation("buyTicket");
return (
...
<span>
{!props.dateRange[0].startDate ||
!props.dateRange[0].endDate
? t("cdr34")
: moment(props.dateRange[0].startDate).format(
"YYYY.MM.DD"
) +
" - " +
moment(props.dateRange[0].endDate).format(
"YYYY.MM.DD"
)}
</span>
解决方案
如果您只想在服务器端进行计算,那么您应该使用 getServerSideProps 中的函数而不是组件的返回块
推荐阅读
- ruby-on-rails - 从 rails(后端)获取方法的响应到 Vue 模块
- fabricjs - Fabricjs 的对象组未显示且行为不正确
- azure - Azure Functions Core Tools 无法安装绑定所需的扩展,在 Ubuntu 服务器中出现 SSL 错误
- autofac - Autofac 是否支持在 Blazor WebAssembly 延迟加载程序集中注册服务
- javascript - Selenium 问题当在网站上以 DIV 形式提供表格数据时,在 DIV 内我每行都有一个 div
- react-native - SVG 被切入 React Native
- c - 与 Linux 相比,Windows/MSYS2 上的双重初始化错误
- arrays - 将熊猫数据框转换为 json
- sql - BigQuery/Tableau 日期错误:无效日期:“2021 年 2 月 5 日”
- java - 使用 MutableLiveData 时是否必须通知我的 ListAdapter?