Skip to content

When does Preact re-render function components? #2877

Answered by JoviDeCroock
emschwartz asked this question in Q&A
Discussion options

You must be logged in to vote

Hey 👋

Interesting question, let's take the following scenario to complete your example:

const Child = () => {
  const [state] = useStore();
  return (<p>{state.text}</p>
}

Context will emit to this consumer every time anything in the object changes, however this does not mean that anything will change to this <p> tag. In this case we have two possible scenario's:

  • someone changed text, this means that we'll have to update the text-node from oldValue to newValue
  • text remains the same, we check if something change and move away.

So concluding, without a change to state.text no expensive operations to the DOM will happen.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@emschwartz
Comment options

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