Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's not about useEffect. If a Component renders a text field, that text field has additional state (e.g. cursor position) which is not part of the model. That's one reason why the UI is not a pure function.


Couldn't this be solved by acknowledging that there is application-domain state (such as the value of the text field) and UI state (such as the cursor position and selection), which can be represented by an application-domain model and view model respectively, rather than trying to pretend that the latter doesn't exist?

Although if you model all the UI state, maybe you just end up with the DOM?



This feels like saying Haskell doesn't have pure functions because they don't account for cosmic ray bit flips.


No, this implicit state is a very practical concern in React. For example see this highly upvoted SO post. Text fields lose focus on re-render; the solution is to use a unique key so that the view gets re-used and the implicit state is preserved.

https://stackoverflow.com/questions/22573494/react-js-input-...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: