kentcdodds / advanced-react-patterns-v2

Created with CodeSandbox
https://codesandbox.io/s/github/kentcdodds/advanced-react-patterns-v2
1.51k stars 568 forks source link

Control Props with state reducer #49

Closed Wgil closed 6 years ago

Wgil commented 6 years ago

Hello!

I'm currently studying this pattern and I was wondering what could be the utility of having a state reducer prop. In this example we are initializing our on state with initial props and telling the user about state changes using onStateChange prop and not using the state reducer at all. I guess the state reducer could be useful to also manage different pieces of state internally. Thus, having controlled and non-controlled properties at the same time. Is this the utility of the pattern?

Thanks for this very useful course.

kentcdodds commented 6 years ago

Yes, so the benefit is that your component can support multiple use cases with varying levels of ease.

I'm glad you enjoy the course!

Wgil commented 6 years ago

Thank you!