Question: My question is really simple. I want to call the `useState` hook conditionally. I know this is not allowed in react, and that is why I'm here.

My use case is: I have an array of "comments". For each comment, I want to allow it to be liked based on whether the user is logged in or not. For this, I am using a `hasLiked` state. Now the problem is that if the user is not logged in, then this state is redundant and I don't want it.

Here is the code to make it clearer:

```
export default function Comment() {
    const isLoggedIn = someAuthAPI();
    const [hasLiked, setHasLiked] = useState(false) // this is the line that I want to call conditionally
    // ...
    return <div>...</div>
}

```

I want to do this:

```
export default function Comment() {
    const isLoggedIn = someAuthAPI();
    if (isLoggedIn){
        const [hasLiked, setHasLiked] = useState(false) // this is obviously not allowed and will throw an error
    }
    // ...
    return <div>...</div>
}

```

I searched for a solution but could not find anything useful. Most answers are either outdated or suggest using a third party library.

To reiterate, I just want to know if there is a way to make a state conditionally defined. I know I can do

```
const [hasLiked, setHasLiked] = useState(isLoggedIn ? false : null) // or undefined

```

but that is not I want here. I want to prevent the hook call altogether. This is because the example that I have taken here may not use much memory, but what I am using it for is quite memory demanding.

Answer: 
You can use getCell with the cRow variable after getRangeBetweenHeaderAndTotal() to get a specific cell range. Once you have that range, you can read its value using getValue(). And you can write a value to that range using setValue(). You can see an example of how to do that below:

```
function main(workbook: ExcelScript.Workbook)
{
  let cRow: number = 1;
  let tbl: ExcelScript.Table = workbook.getTable("table1");
  let rowCell: ExcelScript.Range = tbl.getColumnByName("SomeCol").getRangeBetweenHeaderAndTotal().getCell(cRow,0);
  let rowValue: string = rowCell.getValue() as string;
  rowCell.setValue("some updated value");
}

```
Can get the value by using the worksheet cell, but I would really like to reference the table itself to not have any issues if things are moved around and such..

```
let col = collectionTable.getColumnByName("SomeCol").getIndex(); 

// if table starts at beginning of sheet, or else have to offset col and row..
let cell = dataSheet.getCell(requestRow + 1, col);

cell.setValue(value);

```