I need your help to understand this

  • uunicode-1339712969587687497

    unicodes

    29 days ago

    In many tutorials, I have seen this solution being used to show or hide content based on whether there is information in an API output.

    At first glance, it seems like it should return false, but it doesn’t because the console log contains nothing. It’s not a space or any visible character—it’s something that has a "size" of zero but evaluates as true in a boolean context.

    I was looking for a quick solution to show and hide content, and the only approach I found was: API output > size > greater than 0. However, this isn’t perfect because it takes a fraction of a second to compute, causing unintended elements to briefly appear.

    Another approach I found was setting a default value of false for everything and updating it to true on load if the value exists. But this results in unnecessary variables in the app.

    What method do you use to show or hide content based on API output?
    1339712970095067188-Screenshot_2025-02-13_at_23.39.22.png
    1339712969805922407-Screenshot_2025-02-13_at_23.19.20.png
  • andreasmoller-1339716748965838860

    Andreas Møller

    29 days ago

    the value of request-get is an empty string
    ""
  • in toddle only false and null are considered false.
  • uunicode-1339718849922076846

    unicodes

    29 days ago

    Thank you Andreas. I have to figure out something better than measuring the output ☺️
  • andreasmoller-1339721345205796955

    Andreas Møller

    29 days ago

    You could use a formula like this
    1339721344983764992-CleanShot_2025-02-13_at_23.14.072x.png
    🙏1
    🙏1
  • uunicode-1339722881256656946

    unicodes

    29 days ago

    Inspired by your example I did this. Considering it always outputs an empty string (if is null), which could be considered as a state (like false, true, or null), I tried comparing it with another empty string, and it seems to work.
    1339722881046810694-Screenshot_2025-02-14_at_00.17.40.png
  • uunicode-1339723422845894806

    unicodes

    29 days ago

    But your works better 🥰 , is more logical and efficient.
  • Thank you Andreas!
  • andreasmoller-1339725290452287580

    Andreas Møller

    29 days ago

    You are welcome.

Stop scrolling. Start building.

toddle is a visual web app builder that rivals custom code — but accessible to your entire team!

Try toddle — it's free!

© Copyright 2024 toddle. All rights reserved.