PricingBlog

How to access information in an Input field (which is a component)?

  • larshaehre-1259202448896036925

    Lars Hæhre

    1 year ago

    What is the best way to access information in a component in another component? I want to submit an email address (Input field is a component) when a button is clicked (Button is a component). How can the Button-component get access to the text in the input field?

    Would it be to create an event on the Input field component that updates a variable in the parent (Page) every time the text is changed? And then use that variable as the input? Or any better ways to do this?
  • larshaehre-1259227635511328778

    Lars Hæhre

    1 year ago

    Some additional information:
    Component 1 here is the input field where the user inputs his/hers email.

    Component 2 is the button that triggers an API to signup a user. This Component needs to get the information (that is the email address) from Component 1.
    1259227635305676800-image.png
  • lucasg-1259235058074517524

    Lucas G

    1 year ago

    Since the input is a component, it should already have an event that sends back the input
  • lucasg-1259235323439742986

    Lucas G

    1 year ago

    So yes, you're on the right track
  • Send the data back to use in your API