renatorib / react-powerplug

:electric_plug: Renderless Containers
https://renatorib.github.io/react-powerplug
MIT License
2.68k stars 101 forks source link

`State` component implements `Value` component & not the other way around #180

Closed harrysolovay closed 5 years ago

harrysolovay commented 5 years ago

Hi,

I have a question about the component hierarchy: Why is it that the State component is using the Value component? It appears Value implements setState within its _set method, which scopes it to the state's value member. Then, the State component is wrapped with Value, which implements a new setState that calls the _set passed from Value... this means that setState/_set is unnecessarily implemented twice... also, the State component scopes setState to value (internally), which isn't necessary (might as well use the built-in setState). Also, there's an extra container in the mix. Please let me know if there was some other thinking behind this... I don't mean to sound critical... I'm just looking for opportunities to contribute to this library. I really dig the render-props pattern & wanna improve/add to this lib with features more geared toward global state management.

Please let me know your thoughts & thanks for looking this over.

Kind regards,

Harry

TrySound commented 5 years ago

@harrysolovay It's because of reset function. It's not possible to implement reset for "native" setState because it's always extended, not overridden.

harrysolovay commented 5 years ago

Ahhh, I see. That makes a lot of sense. Thank you 👍

renatorib commented 5 years ago

It may not seem like it, but it simplifies a lot as well! Look https://github.com/renatorib/react-powerplug/pull/149