question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] How to implement "click on a button then run an async action" in an elegant way?

See original GitHub issue

I see the examples of async actions are about "running async actions when rendering a component, e.g. https://lostpebble.github.io/pullstate/docs/async-actions-creating

Now I have a different case: In a component, there is a button, when I click on it, it will run some async actions, and rendering different content base on the result of the async action.

I couldn’t find an elegant way to implement it, hope to have your help, thanks!

This is a small demo: https://github.com/freewind-demos/typescript-react-pullstate-async-actions-demo

The RemoteHello1 there is what I want to do (in traditional way), and the RemoteHello2 is what I want to use pullstate’s async actions but failed.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lostpebblecommented, Apr 5, 2020

@freewind , I just updated the project with the new changes I added.

It was actually very simple to add, don’t know what I hadn’t done it yet. Also made creating simple async actions easier, by just passing in a promise directly.

0reactions
freewindcommented, Apr 5, 2020

Thanks, the code is really nice and clean, thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Calling async method on button click - Stack Overflow
I've added async to my button click event handler and am await ing the async task but the async task is still running...
Read more >
Asynchronous JavaScript - Learn web development | MDN
In this module, we take a look at asynchronous JavaScript, why it is important, and how it can be used to effectively handle...
Read more >
Getting Started With Async Features in Python
This step-by-step tutorial gives you the tools you need to start making asynchronous programming techniques a part of your repertoire.
Read more >
Using async-await feature in Angular | by Balram Chavan
In Angular application, we can use Rx.js to leverage power of Observables, Subject, BehaviorSubject etc for writing asynchronous code in elegant way.
Read more >
Introduction to Cypress - Cypress Documentation
But the rule of thumb is simple: If you perform an action, like navigating the page, clicking a button or scrolling the viewport,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found