how does react state work under the hood