Q:

How to update state inside conditional logic?

i need to update my state with the setExpression hook only if the condition is met. I've just red that this is not supposed to work as you cannot call hooks from inside conditional logic but i haven't been able to find any workaround. How can i do this? 
let handleOperator = e => {
  let last = expression[expression.length - 1]
  if (last === "+" || last === "-" || last === "*" || last === "/") {
    setExpression(expression.slice(0, -1))
  }
  pushToString(e)
}

A:

Your code is perfectly valid. You can call the setExpression function that is returned from useState (e.g. const [expression, setExpression] = useState('');) wherever you like, but you can not use the hook itself (useState in this example) inside conditional logic.

