Đặt câu hỏi và nhận tóm tắt tài liệu bằng cách tham chiếu trang này và nhà cung cấp AI bạn chọn
Tài liệu này đã lỗi thời, phiên bản gốc đã được cập nhật vào 21 tháng 1, 2026.
Xem tài liệu tiếng AnhLịch sử phiên bản
- "Khởi tạo lịch sử"v5.5.1029/6/2025
Nội dung của trang này đã được dịch bằng AI.
Xem phiên bản mới nhất của nội dung gốc bằng tiếng AnhIf you have an idea for improving this documentation, please feel free to contribute by submitting a pull request on GitHub.
GitHub link to the documentationCopy doc Markdown to clipboard
Tài liệu Hook useIntlayer
Hook useIntlayer cho phép bạn truy xuất nội dung được bản địa hóa từ một từ điển bằng khóa của nó. Nó dựa trên useDictionary nhưng tự động đưa vào một phiên bản tối ưu hóa của từ điển từ các khai báo được tạo ra.
Ví dụ sử dụng trong React
Minh họa hook useIntlayer trong một component React:
Sao chép mã vào clipboard
import type { FC } from "react";
import { ClientComponentExample, ServerComponentExample } from "@components";
import { IntlayerProvider } from "react-intlayer";
import { useIntlayer, IntlayerServerProvider } from "react-intlayer/server";
import { Locales } from "intlayer";
const App: FC<{ locale: Locales }> = ({ locale }) => {
const content = useIntlayer("homepage", locale);
return (
<>
<p>{content.introduction}</p>
<IntlayerProvider locale={locale}>
<ClientComponentExample />
</IntlayerProvider>
<IntlayerServerProvider locale={locale}>
<ServerComponentExample />
</IntlayerServerProvider>
</>
);
};Sao chép mã vào clipboard
import type { FC } from "react";
import { useIntlayer } from "react-intlayer";
const ComponentExample: FC = () => {
const content = useIntlayer("component-example");
return (
<div>
<h1>{content.title}</h1>
<p>{content.description}</p>
</div>
);
};Sao chép mã vào clipboard
import { useIntlayer } from "react-intlayer/server";
const ServerComponentExample = () => {
const content = useIntlayer("server-component");
return (
<div>
<h1>{content.title}</h1>
<p>{content.description}</p>
</div>
);
};Tài nguyên Bổ sung
- Trình chỉnh sửa trực quan Intlayer: Để có trải nghiệm quản lý nội dung trực quan hơn, hãy tham khảo tài liệu trình chỉnh sửa trực quan tại đây.
Phần này tập trung cụ thể vào việc tích hợp hook useIntlayer trong các ứng dụng React, giúp đơn giản hóa quá trình bản địa hóa và đảm bảo tính nhất quán của nội dung trên các ngôn ngữ khác nhau.