With this function I've implemented both `state` and `hiddenState`. It's a lot less clear but perhaps a bit more flexible. I was considering keeping it as a public function but we can keep it un-exported if you prefer that.