Default selecting an item

const [isActive, setIsActive] = useState(false);
const handleClick = (id) => {
setIsActive(id);
};

    {globalFilter.map((data, index) => (
  • handleClick(index)} > {data.text}
  • ))}

this is my code, I am setting an active class while clicking one of the items and I want one first one should always be selected when I open this dialogue.

is the main line to address. The false argument for useState is setting the default value of isActive. You probably want that to be 0 to select the first item by default:

const [isActive, setIsActive] = useState(0);

Thank You, this works.

need default active state for array selector as well.

const [subCategoryData, setSubCategoryData] = useState();

I would change the name from isActive to activeId. That is a better description of the value the variable holds. isActive makes it sound as if the value will only be Boolean.