re: React hooks: get the current state, back to the future VIEW POST


I have been writing OO code in Java for nearly three decades, I have been writing functional code for about three months now so excuse me if this sounds like I'm just ignorant of a few things. My first question is, isn't it functional programming's goal to not maintain state information between method calls? Second is, if you combine this with TypeScript, don't you now just have plain ol' Java again?


Yes, in general functional programming styles tend towards stateless code and immutable data.

React hooks are constructed specifically to access and change stateful information in the context of a functional component. There are ways to solve this issue using stateless functional programming practices, but I don't think it's the react team's goal to enforce any particular programming style. Thus, hooks are a pragmatic solution.

I don't think Typescript and React hooks (or even stateful programming) equates to Java. For example, while Java 8 introduced lambda expressions, lambdas and first class functions have been a part of javascript since its creation. While javascript and typescript have implemented the class keyword, the inheritance structure of javascript is still prototypal, not class based.

Like react, Typescript and javascript are pragmatic in their approach to different coding styles. For example, you can generally approach React from an object oriented standpoint and never write a single functional component. Likewise, you could eschew react hooks and write a completely stateless react application that passes all data out from a single state monad.

Does this help at all?

code of conduct - report abuse