Skip to content

Instantly share code, notes, and snippets.

@viknedus
Created August 9, 2021 09:59
Show Gist options
  • Save viknedus/cf03616ee111170572b4fdbbfba938eb to your computer and use it in GitHub Desktop.
Save viknedus/cf03616ee111170572b4fdbbfba938eb to your computer and use it in GitHub Desktop.
Randomize Hex color for React
const randomHexColor = () => {
return '#000000'.replace(/0/g, () => {
return (~~(Math.random() * 16)).toString(16);
});
};
// CSS
* {backgroundColor: randomHexColor(),}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment