When to pass a function to useState and setState