Apparently you can't name the second parameter whatever you want. The name of the second parameter must be state. Not knowing this information, I was using a capitalised S. Putting it to lowercase solved the problem.
state
S