How do I prevent the api call from being run every time sate is changed, and only run on button pres

I would love some help on how I can make sure the api call is only run when the button is pressed and not every time state changes. I want to pass the state variables to the usetextstream function so that I can stream text from chatgpt to the frontend. But whenever any state changes the usetextstream function is run, this is creating a user experience where anything the user does makes an api call and starts streaming text. I would love if it only ran when the user clicks the generate social media post button.
1 Reply
kapa.ai
kapa.ai5mo ago
Hi @haarismian. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Hmm, I don't know enough to give you a confident answer yet. The knowledge sources provided do not contain specific information about handling state changes and API calls in the context of Wasp or React. However, in general, you might want to consider using event handlers in React that trigger your API call only when a specific event (like a button click) occurs. This way, the API call won't be tied to every state change, but only to the specific user action you want. For more specific guidance, I recommend checking out the Wasp documentation (https://wasp-lang.dev/docs) or the React documentation (https://reactjs.org/docs/handling-events.html) on handling events. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @haarismian, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Want results from more Discord servers?
Add your server