假設我有一個 React 組件,它從props
例如以下獲取 Tailwind 類名稱:
import React from "react";
export default function Header({navColor}) {
return (
<nav
className="flex justify-center items-center text-white text-xl h-14"> //I want to add a class that it's name is the (navColor) value to the nav tag
TEST
</nav>
);
}
怎樣才能做到這一點?
uj5u.com熱心網友回復:
您可以使用模板文字來實作這一點
使用${}內部反引號 ``
<nav
className={`flex justify-center items-center text-white text-xl h-14 ${navColor}`}>
TEST
</nav>
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/419523.html
標籤:
