Default selecting an item

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

    {, 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();

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.