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

How to update a property when another has changed? #2

Open
vinyll opened this issue Apr 8, 2020 · 0 comments
Open

How to update a property when another has changed? #2

vinyll opened this issue Apr 8, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@vinyll
Copy link
Member

vinyll commented Apr 8, 2020

When one property changed from attribute, I want to update another state attribute.

My app

<x-user id=8></x-user>

x-user.js

class XUser {
  init() {
    this.state = { user: {}, id: null }
  }
  async connected() {
    const response = await request.get(`/api/user/${this.state.id}`)
    this.state.user = response.data
  }
}

Now that state.user is initialized when the component is connected, changing <x-user id=8> to <x-user id=9> won't change state.user as connected() is not called anymore.

Suggestions:

  • adding a lifecycle event changed(prop, newValue, oldValue)
  • or auto calling a method onIdChanged(newValue, oldValue)
@vinyll vinyll added the enhancement New feature or request label Apr 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant