Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why are there no control props for the state management components? #159

Closed
fea17e86 opened this issue Aug 13, 2018 · 3 comments
Closed

Comments

@fea17e86
Copy link

I was wondering why components like State, Toggle and Value accept an initial value but don't accept a controling value?

Something like this:

<State state={myState}>
  ...
</State>

Why do you need that? I used State to represent the state of a form, which was initially populated by an object. Next the differrent form components would modify the local State. And in the end that State would be submitted to the remote API. This resulted in an updated object, which then populated the form State again. Because State does not accept changed props I had to write my own component.

My guess was you wanted to skip having to compare states of State to make it work. Or is there more to it?

@TrySound
Copy link
Collaborator

TrySound commented Aug 13, 2018

If you want to control your components then you don't need intermediate state. Just pass data directly to them. The idea of this project is the same as regular react state: localizing state management where the state shouldn't be lifted. In all other cases you should always lift your state in parent components.

@TrySound
Copy link
Collaborator

However there is a trick. To reset component state (any powerplug component) you may pass another key prop. For example

<plug.Input initial={props.receivedFromServerValue} key={props.receivedFromServerValue}>
  {input =>
    <input {...input.bind} />
  }
</plug.Input>

@fea17e86
Copy link
Author

If you want to control your components then you don't need intermediate state. Just pass data directly to them. The idea of this project is the same as regular react state: localizing state management where the state shouldn't be lifted. In all other cases you should always lift your state in parent components.

Yes, I thought about that. But with the possibilities of render prop components, parents which exist for state management are disappearing, at least from my code. And at least in the use case that I tackled it would only increase the amount of code, whithout increasing the readability or any other quality indicator. But I do understand that you want to follow a certain set of principles. It keeps the project cleaner.

Thank you for the response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants