Pass data through attributes or URL parameters?

  • Vizualinx

    1 month ago

    In my app i have a lot of modal popups (like contact details, donation details, transaction details etc).

    What would be the best way to pass data?

    I can think of 3 ways:

    On click of a row,
    1: I can pass the whole row to the popup via attributes.

    2: only pass the row id through attributes and make a new APl call inside the modal.

    3: pass the row id through URL parameters and create the APl call in the modal. What is the best way to do it?
  • Vizualinx

    1 month ago

    Pass data through attributes or URL parameters?
  • Tom Ireland

    1 month ago

    Disclaimer: This is based on my knowledge of web components so far, so there could be better ways to do things.

    I think it really depends on the scenario. If the idea is that the modal is generic enough for reuse in multiple scenarios, setting an API call within the context of a component means that it becomes a bit restrictive.

    At the moment, I opt for events to trigger on-page API calls, so I can have a modal for multiple use-cases and then just use the click event to trigger whatever API call there is on the page.

    Then there's error management, etc., so it's not a trivial task.

    Would be cool to have some place to discuss all these scenarios and have everyone contribute in their experience.
    💯1
  • Lucas G

    1 month ago

    It sounds like you already have the data at a higher level so calling the API again would be inefficient
    ☝️1
  • Pass the data into the component via attributes or contexts
  • Alex

    1 month ago

    I just call APIs that set variables and then I bind the inputs. But I’m not using components. I’m more primitive

    So I’m interested to see how people use form components for multiple uses
  • Chris Laupama

    1 month ago

    The best approach depends on your specific requirements, but here's a general guideline:

    Use Approach #1 (passing complete data) if:

    - Your data is relatively stable
    - Quick modal opening is important
    - The data size per row is reasonable
    - You don't need deep linking

    Use Approach #2 (ID + new API call) if:

    - Data freshness is critical
    - Row data is large
    - You need to optimize initial page load
    - You have good network conditions

    Use Approach #3 (URL parameters) if:

    - You need shareable/bookmarkable modals
    - SEO for modal content is important
    - Deep linking is a requirement
    - You're building a document-centric application

    For most applications, I would recommend Approach #1 with a hybrid strategy:

    - Pass the complete row data for immediate display
    - Optionally refresh the data in the background if the modal stays open for a while or if specific actions require fresh data
    - Implement a simple cache invalidation strategy
    👆1
  • Lucas G

    1 month ago

    Thanks ChrisAI
    😂1
  • Our new toddle friend
  • Chris Laupama

    1 month ago

    Lucas G puts the G in GPT
  • Vizualinx

    1 month ago

    Thanks everyone for your advice!

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.