Sunday, December 17, 2023

Global colors Use (Create color Variable) in ReactJS

 Global colors Use (Create color Variable) in ReactJS 


Step 1

Create a new file names colors.js in your project.


Step 2

Let’s start adding colors to our colors.js file.


import React from 'react';

export const COLOR={
    primary: "green",
    secondary: "red"
}

Step 3

Let’s start to usage.

import { COLORS } from ‘<current dir to parent dir — src/>/values/colors.js’

// { } is very important without this showing error :

export 'default' (imported as 'COLOR') was not found in '../../utils/Mycolor' (possible exports: COLOR)


import { MYCOLOR }  from '../../utils/Mycolor';

// Calling this color here

<Button href='/login' style={{color: 'white' , backgroundColor: MYCOLOR.primary}} >Sign In</Button>

No comments:

Post a Comment