4 ms·
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'
by ridiculous_fish 4y ago
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.
- Kaze404 4y agoThis feels like saying Haskell doesn't have pure functions because they don't account for cosmic ray bit flips.
- ridiculous_fish 4y agoNo, 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-losing-focus-when-rerendering https://stackoverflow.com/questions/22573494/react-js-input-...
- ptx 4y agoCouldn'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?
- ridiculous_fish 4y agoYes, this is known as MVVM. https://en.wikipedia.org/wiki/Model–view–viewmodel https://en.wikipedia.org/wiki/Model–view–viewmodel