Closed 01kingmaker01 closed 2 years ago
Hey there
Unfortunately, twin can't translate random values - you'll have to use plain old css for that 😭
Something like this:
const Component = () => {
const [randomColor, setRandomColor] = useState(null)
const getRandomColor = () =>
`hsl(${360 * Math.random()}, ${25 + 70 * Math.random()}%, ${
75 + 10 * Math.random()
}%)`
useEffect(() => {
setRandomColor(getRandomColor())
}, [])
const styles = [
tw`to-black bg-gradient-to-b`,
{
'--tw-gradient-from': randomColor,
'--tw-gradient-stops': `var(--tw-gradient-from), var(--tw-gradient-to, ${randomColor})`,
},
]
return <div css={styles}>Something...</div>
}
Thanks, @ben-rogerson and team. Twin.macro is fantastic 💖
Hey, I am using NextJS + styled-components template. I want help in making a gradient of random color to black
SomeThing Like This
I am getting error
Below is my code ⬇️⬇️⬇️