I have a react component with the following code:
function DoubleCell(props: Props) {
return (
<div className="DoubleCell flex w-2/3 mx-auto">
<div className={`formula_dbl ${props.formula_width ? `w-${props.formula_width}` : "w-1/2"}`}>
{props.formula}
</div>
<div className={`desc_dbl ${props.description_width? `w-${props.description_width}`:"w-1/2"}`}>
{props.description}
</div>
</div>
);
}
It is basically a div taking 2 thirds of a screen width with 2 nested divs inside. Their contents are defined elsewhere when they are called as a component. Now one interesting thing is that I want the nested divs to optionally have their widths defined...
Here is my Props interface.
interface Props {
formula: String;
description: String;
formula_width?: String;
description_width?: String;
}
All of this is code is present in components/FormulaCell.tsx
Here is my _app.tsx
file where I start calling the component:
import '@/styles/globals.css'
import DoubleCell from "./components/FormulaCell"
const formulae = [
["f1","f1-uses","5/6", "1/6"],
["f2","f2-uses","4/6", "2/6"],
["f3","f3-uses","3/6", "3/6"],
["f4","f4-uses","2/6", "4/6"],
["f5","f5-uses","1/6", "5/6"],
]
function App(){
return (
<>
{formulae.map((formula, index) => (
<DoubleCell
key={index}
formula={formula[0]}
description={formula[1]}
formula_width={formula[2]}
description_width={formula[3]}/>
))}
</>
)
}
export default App;
In the above code where I defined the array of values to be used as parameters for the <DoubleCell/>
component...
["f1","f1-uses","5/6", "1/6"],
["f2","f2-uses","4/6", "2/6"],
["f3","f3-uses","3/6", "3/6"],
["f4","f4-uses","2/6", "4/6"],
["f5","f5-uses","1/6", "5/6"]
The content (eg: f1
and f1-uses
) works, but the tailwind width classes don't work.
I tried look for a solution to this problem and found this post here
Where they said that styles were being removed by tailwind as they were not used, and that they had created an invisible div with the required classes for tailwind to load them. The problem is that my project will soon use Arbitrary values, which I many not be able to put in an invisible div (as it can be literally anything).