Skip to content
Discussion options

You must be logged in to vote

You can just do form.data.length - under the hood it's the same as form.data.get(/*shallow*/ true).length. Shallow makes it re-compute only if an element is added/removed to the array, and ignore modifications within individual elements, so that may be better for performance if elements change a lot.

But for Show you can just give if a function - you don't need to create a computed for it. And since else doesn't change based on any observables, you can just give it the string without a function.

So this should work:

function App () {
  const form = useObservable({ data: [] })

  return (
    <Show if={() => form.data.length > 0} else="Start typing">
      <For
        optimized
        each=

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by darklight9811
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