Google script (custom function) doesn’t get updated inside a cell

I have this function :

function clastrow(targetsheet) {
  var SS= SpreadsheetApp.getActiveSpreadsheet();
  var Sheet = SS.getSheetByName(targetsheet);
  return(Sheet.getLastRow());
}

function clastcol(targetsheet) {
  var SS= SpreadsheetApp.getActiveSpreadsheet();
  var Sheet = SS.getSheetByName(targetsheet);
  return(Sheet.getLastColumn());
}

It simply will return the last row/col of the target sheet. Then i use it for example in cell A1 :

=clastrow(B1)

where B1 contains the sheetname of target sheet to be calculated. It works but when i modify the target sheet , the output value of this custom function didn’t get updated.

Finally, rather than using it as formula, i end up adding a button and assign the script to manually update the value.

How can i fix this if i want to keep using it as formula ? is it normal that the function won’t update automatically ?