More about state parameter can be found from this answer.
Where to generate the state and where to store will depend on the nature of your application. Regardless from client type, what client must do is to validate state parameter in authorization code response.
For a single page application, which does not contain a backend, state will have to be generate and store in the browser itself. Once response arrives, state value will have to be compared.
For a native application (ex:- Mobile app), state could be stored in application memory. It can be appended in authorization request. When response comes, it can be validated from memory
If application desire, state can be stored in a backend (ex:- server). This can be considered more secure (compared to SPA) given that no one can intercept/obtain the value other than from request itself. Once redirect occur, backend can validate the response parameters. Moreover, it can be used to correlate client session.
Also, stealing state value is only valuable for the party which tries to make a CSRF attack. But be mindful to generate state values that cannot be guessed. Further reading for storage - 3.6. "state" Parameter