Skip to content

Access useState hook in Action #10264

Closed Answered by tophboogie
tophboogie asked this question in Q&A
Discussion options

You must be logged in to vote

I ended up getting some advice in the Discord server. In case anyone else stumbles upon this question, the best method is to use JSON.serialize to hold the array in a hidden form element.

<Form><input name="data" type="hidden" value={JSON.stringify(state)} /></Form>

Then in the action use JSON.parse to get the array back and include in the api call.

export async function action({ request, params }) { const body = Object.fromEntries(await request.formData()); body.data = JSON.parse(body.data); return callAPI(body); }

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@me-sajib
Comment options

Answer selected by tophboogie
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants