Skip to content

When to use bind vs hooks? #456

Closed Answered by Przegryw321
rafaeljacov asked this question in Q&A
Discussion options

You must be logged in to vote

Use bind when you're just assigning a value, use hook when you need to do something more.

Here's an example of my network widget, it sets the icon based on a function, but also controls the class to change the color of the icon.

const network_status = Widget.Label({
  className: 'bar-network',
  setup: self => self.hook(network, self => {
    self.label = get_network_icon(network)
    self.toggleClassName('bar-network-disconnected', !network.primary)
    self.toggleClassName(
      'bar-network-connecting',
      network.wired.internet == "connecting" || network.wifi.internet == "connecting"
    )
  })
})

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by rafaeljacov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants