[英]How can I solve: “Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.”
[英]How do I return nothing instead of a blank space in this if statement?
您可以看到我使用 "" 使 if 语句在某些情况下不返回任何内容,但实际上它返回一个空格。 我不想要那个空白,我可以用什么来代替?
if (n >= 20000 && n < 100000) {
result = `${tens[Math.floor(n / 10000) - 1]} ${
Math.floor((n % 10000) / 1000) != 0
? num[Math.floor((n % 10000) / 1000)]
: ""
} thousand ${n % 1000 != 0 ? number2words(n % 1000) : ""}`;
return result.trim();
}
当条件为真时,您将不得不重组您的代码并移动包含空间。
const tensText = tens[Math.floor(n / 10000) - 1];
const divisible = Math.floor((n % 10000) / 1000);
const hundredsText = divisible != 0 ? ` ${num[divisible]}` : '';
const thousandsText = n % 1000 != 0 ? ` ${number2words(n % 1000)}` : '';
result = `${tensText}${hundredsText} thousand${thousandsText}`;
要不返回任何内容,您可以使用return;
但是,如果一种情况返回一个字符串,您可能应该始终返回一个字符串以保持一致性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.