Skip to content

Does the writing of nested createMemo make sense? #351

Answered by ryansolid
oligay666 asked this question in Q&A
Discussion options

You must be logged in to vote

The problem with this example is you create and read at the same level. There is no purpose there as it basically cancels itself out. Computations (like Memos) re-eval when their dependencies change, and since you are creating reading it at the same scope, the second they update their parent will re-evaluate releasing them and starting new.

This example actually doesn't benefit at all from the outer createMemo since it is only tracking the memos it creates. You could just remove it and it would do exactly what you want.

The value of nested createMemo's is more like this:

const value  = createMemo(() => {
  const result = calculateSomethingExpensiveButIsRarelyExecuted(someInput())
  return c…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by ryansolid
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
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
Converted from issue

This discussion was converted from issue #350 on February 20, 2021 09:02.