Go Pro Sign Up Login

Buy Now and unlock this series

$

49

.99

$

39

.99

yours forever

Become a Pro and unlock everything

$

24

.99

per month

Actions In Remix

Downloads

Become a pro to download code and videos

Comments

mike g

about 1 month ago [edited]

Suppose I have a button, that calls a third-party sdk which only works client-side.

Once the async 3rd party call comes back, I want to POST to my server. How should I set this up with a remix action? My approach has been to attach a handler to the form, await and then use useSubmit().

const submit = useSubmit(); let thirdPartyAPIResponse;

<form
  onSubmit={(event) => {
    event.preventDefault();
    // Call 3rd party sdk
    thirdPartyAPIResponse = await thirdPartyAPICall();
    submit(event.currentTarget);
  }}
>
<input type="hidden" value={thirdPartyApiResponse} />

Is that the correct approach?

Want to join the conversation?

Become a Pro member today!