Skip to content

What causes the observer to re-render a component? #3244

Answered by urugator
joaovct asked this question in Q&A
Discussion options

You must be logged in to vote

Generally speaking if it wouldn't change the output it's not relevant, eg:

// Conditions
observer(({ store }) => {  
  return store.cond ? store.a : store.b
  // if `store.cond` is `true`, `store.b++` is NOT relevant
})

// Object props
observer(({ store }) => {
  return store.a;
  // `store.b++` is NOT relevant
  // `store.a++` IS relevant
})

// Passthrough
observer(({ store }) => {    
  return <User user={store.users[0]}/>
  // `store.users[0].name = "new name"` is NOT relevant for this component
  // it can be relevant for User component, so it may need to be observer
  // `store.users = [{ name: "foo" }]` IS relevant
  // `store.users[0] = { name: "foo" }` IS relevant
})

Note in all…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@joaovct
Comment options

@urugator
Comment options

@joaovct
Comment options

Answer selected by joaovct
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