I have two functions
let [selected, selectedIds] = React.useState<readonly string[]>([]);
- This function is stored the given id in the array
const addSelectedIds = (id) => {
// Adding id with some calculation
selectedIds(id);
}
- This function is use to check the given id is available in array or nott
checkSelectedIds = (id) => {
const isSelected = (id) => selectedIds.indexOf(id) !== -1;
// Which return false, but its already added from first method
// Here i need isSelected value as true because its already added from first method
}
These function is call with one onClick event like below
<tr onClick={() => {addSelectedIds(id); checkSelectedIds(id)}} ></tr>
I need selectedIds array in the second method checkSelectedIds() where have to check the selected id is available in array or not, but in the checkSelectedIds() selectedIds are return null So thats why am getting null values in array