In this React eCommerce website, we are going to learn how to Filter Products based on Colors in React JS. This will help us to categorize our products more effectively on our eCommerce website.
Hello what's up guys my name is Vinod
Bahadur Thapa Today we are going to see
Colors filter in our react e-commerce website
So guys let me tell you what it is
So far we have seen everything We have also
obtained the data of our colors If you haven 't
watched the previous video then check it
out Today we have to see this functionality
Wherever I select any
color on its base I
can see my color I mean
I can see my product
Thanks for 5 lakh subscribers This is only
possible because of you
And thanks to all the
members Your support
matters a lot So guys it
is very simple I told you two ways yesterday
With which you can get the data of an
array union We have
done that Now I have to
run the loop of my
colors data So that my
user interface Looks something like this
So let's tackle it
first So guys we have
to go below this We
have again one class So
we have a filter colors
And one more Simply
colors So let's see I am adding an extra
Colors class I have to write
Colors
perfect Now
we have to tackle the
filter So I am writing
filter color
style Filter
-color-style
And spelling
You have to
write correctly
This is it Now guys
What I have to do is create the circles
that you can see
And obviously
my data is
inside all the colors data
so here I
have to run my
colors data this portion
enter now I
have to run map
method anonymous
function
or callback my
current color
write here current color
And obviously Index
number So
here I have to
Return That is a button So I forgot to do that I
want that color in this
button So without thinking
I will write current
color If I
write this muc
And if I run here
you can see my colors
I got my colors now
nothing is going to
happen but if I click
here my work should
be done so I have to run in this button
I have to write many things here
First of all whenever you
use a button it is very important to tell you the type attribute
Then class name
I am going to write here
That is a condition
When were dealing with colors
Then I wrote
Let me do one thing
First I write normal
Button style
If I write only this much
And see guys I'm
getting the same color
Now I will get
unique color
When I will tackle
Style property
Javascript world
This is my object world
And my background color
I am writing here Will be
equal to current color I
have to write Current color
IT SHOULD BE IN
CAPS AND I WILL LEAVE
IT AS IT IS LET'S SEE IF I RUN HERE I
GOT MY COLORS NOW I
NEED ALL I WILL TELL
YOU IN A WHILE I GOT
MY CURRENT COLORS
Now guys I don't
need hex
code So guys
I will run here I want to
show you one
thing If my original
color is equal to
Then show Or don't
show Basically here
I am leaving it as
it is If my colors
In my filter context
Oh sorry it's a color
This is your color
And here I have to run on top And I have to represent
this color If my This
color If my color
matches my current color
Then I have to show
Else it will be null
If you see Everything
is fine In the same
way We can play with
background color We
will see that next I
will give you a tas
I have to filter it
I am leaving it as it is
And it happened
Below it
Obviously whenever someone clicks on it
I have to filter out
My products
Whenever someone clicks
We have an update filter
Update filters
Update filter value
And then paste
Obviously
I have to pass a
key Whatever it is
So that we can target
individually This is it
My work is done Whenever
someone clicks I have
not passed the value
Value will be again
my current Lm We have already seen in the
button We need
a value Its
name attribute We have
not even written the
name attribute Name
should be Color Name here
It is very important
that both are the same
So name Value Whenever
someone clicks on
it That's it Now I have
to go to the reducer
And again it's super
duper easy If colors
We can't write colors here
We have to write color
Because I have written color
And I am getting it
If there is a color
Obviously I will copy it
And paste it here
But this time
I don't need this
You tell me How will
I know
Which color the user has
selected
Because our actual
data It doesn 't
have one
color Multiple colors One galaxy Galaxy W20
It has 3 available colors
Available in 3 color variants
It is available
You can't say
Exactly Like the current element
Dot colors
I mean equal to equal to color
Because it is an array
I can't do
that What can I
do One by
one Match this color
We need that
Now you think
Which filter
method should I use because I can't
use triple equal to
Because I have a color
Let's say the user selected red
Now
How will I know
In this field
In this array
Is there a red color
RGB
But how will I know
User selected red
And I have to match it
How can I do
that You think
This is my colors
This is an array
We have an include method
Which we are applying
Let's see
My current element
I mean one by one
Current element
Dot colors
Dot
I have to use include method
The color passed by the user
Is it present or not
Suppose the user selected red
This array
Colors
Is there a red color
First check
Second check
On the spot
This is it
Now
The current element is not
defined Where The current element is not
defined Where Filter
section dot js This is the
filter section The current
element is not
defined Current
element We have
used current color Let's
save it Perfec
Refresh for the first time Click on
red Galaxy
W20 Red color
is available
All functionality
is not there That's all
for this video But one
thing is left All
functionality is not there
When I click I
want it right I
can't see right
But it will be a
task for you I
will show you When
I run on individual
You can see Tic
All
We need it Again
it's a task You must
practice I 'll
see you
in tomorrow's video
You can see Almost Now we have to Clear
filter This is it for today's
video
I hope
you like this
Like Share
Subscribe Thank
you Subscribe