Update state variable through interaction from custom event component

I am feeling that what I want to do is pretty simple but I am not approaching it correctly.
What I want to do:
I am reading some query parameters from the URL bar in my custom component and seeing how and when they change with useEffect. I want to update one of my state variables with that value when it changes (I don’t know how to do it with an event handler, since there are no events fired using useEffect).
In general terms, how can I receive a prop in my component, do some logic and fire an interaction based on a custom event / function that I launch from wherever I want in my code?

Thank you!

Hello @daniel_grau.

Just to make sure I understand it correctly, you want to change the state of the parent component when something happens inside your custom code component?
If that’s it, your code component should have a eventHandler prop. The eventHandler prop is just a function that is going to get called, like (...args) => void. Inside your useEffect, just call props.eventHandlerPropName() and you can define what the function is going to be in plasmic.

2 Likes

Hi @icaro_guerra, I’ve been working on this for several days. What I want is to use the Interactions from Plasmic to update a previously set state variable (not from the parent, but from the Plasmic environment).
Again, my practical example is:

  1. Get some query parameters from the URL.
  2. Do some logic in my custom components.
  3. According to that, update some variables that I have already created in my page in Plasmic.

Thank you!

It took me some time but I finally got it. Thx!