add "onClick" event in dropdown options list

Viewed 18

I am working on a list of options, so when user clicked one of the options, it will fetch data from that option, such as most popular, and I am trying to add "onClick" event on the codes below and then useState hook to update , but not sure if I should just add after the tag? and should i delete the {{active}} part, I am really not sure why is that relevant? can anyone help me ? thanks!!!

export const sortOptions = [
  { name: "Most Popular", href: "#", current: true },
  { name: "Best Rating", href: "#", current: false },
  { name: "Newest", href: "#", current: false },
  { name: "Price: Low to High", href: "#", current: false },
  { name: "Price: High to Low", href: "#", current: false },
];


                  <div className="py-1">
                      {sortOptions.map((option) => (
                        <Menu.Item key={option.name}>
                          {({ active }) => (
                            <a
                              href={option.href}
                              className={classNames(
                                option.current
                                  ? "font-medium text-gray-900"
                                  : "text-gray-500",
                                active ? "bg-gray-100" : "",
                                "block px-4 py-2 text-sm"
                              )}
                            >
                              {option.name}
                            </a>
                          )}
                        </Menu.Item>
                      ))}
                    </div>
0 Answers
Related