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

> Stateful components don't work so well in React.

They work fine, though managing state outside of components via a state management library is common.

> If you want to update props in a stateful component, the recommendation is to replace the component entirely by changing its key.

Where do you find this recommendation? I’ve never seen anything like it, and keys are usually only used for repeating sets of elements, and you would generally only use a different key if something is not the same logical entity as the thing that previously had the key.

There might be some cases where you want to force a new rather than updated component by the kind of key manipulation you describe, but it's not the general case of prop updates for stateful components.

> It doesn't have incremental screen update, but neither does React, if your components are interactive and stateful.

React does have incremental updates for interactive, stateful components. You can deliberately negate it the way you’ve described, but you should not, generally.



> Where do you find this recommendation?

https://reactjs.org/blog/2018/06/07/you-probably-dont-need-d...

> keys are usually only used for repeating sets of elements

Not true at all!


From the blog you posted:

> In most cases, this is the best way to handle *state that needs to be reset*

You are talking about updating state, react author is talking about resetting. That's a big difference.




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

Search: