In this article, we will review a package named warn-once. You will learn
What is warn-once?
Warn once usage in Refine source code
warn-once code review
if (action && action !== "list") {
const key = `actions.${action}`;
const actionLabel = translate(key);
if (typeof i18nProvider !== "undefined" && actionLabel === key) {
warnOnce(
true,
`[useBreadcrumb]: Breadcrumb missing translate key for the "${action}" action. Please add "actions.${action}" key to your translation file.\nFor more information, see https://refine.dev/docs/api-reference/core/hooks/useBreadcrumb/#i18n-support`,
);
breadcrumbs.push({
label: translate(
`buttons.${action}`,
textTransformers.humanize(action),
),
});
} else {
breadcrumbs.push({
label: translate(key, textTransformers.humanize(action)),
});
}
}
with an example demonstrating the ability to pass n number of message strings as parameters.
Set is used and has check ensures the message gets logged only once.
About me:
Hey, my name is
My website —
Learning platform —
Best practices —
SOCIAL SHARE CARD GENERATOR