Forms with React and Redux


As in object, I’m having a little bit of trouble with understanding what exactly do I have to do in order to get a React and Redux form to correctly be setup to perform a POST request. I have written a CodeSandbox here.

Of course I’m aware that what I have written so far is probably wrong, but the idea is that the Submit button should dispatch an action (currently it just prints the values on the console) which eventually will perform a post request to a server through a Redux thunk. In theory it’s clear, in practice I’m struggling.

Furthermore, even though I’m just testing this with the two datetime fields, eventually my POST request should have more fields than that, some of which (like first name, last name, email and so on) are not part of the form, but depend on an authentication. How can I achieve something like this (i.e. this “merging” of fields from and not from the form)?

I realize I’m showing quite a bit of confusion with this post, this is why I will be ESPECIALLY thankful to anyone who can point me towards a right direction,

I would suggest you update your code with your actual attempt at doing a form POST.

The docs have examples of GET and POST with a todo.

Here is a random video

Thanks! What about the other parts of state I want my dispatcher to save?

What other parts?

I should warn you, I’m really not much of a Redux user so I might not be the best suited to help you with this.

The question was not only on the post request through the form, but also how to “merge” the state and make it get data also from authentication.

For example, I am authenticated, so the server knows some details about me (such as the first name and my email), hence knows it’s me who is compiling the form; the other part was about how to write a reducer to get the state from the form (for the fields pertaining to it) and also from this “metadata”

I would personally look at code examples, articles, and tutorials for that. I’m not sure if anyone can give a simple answer to those questions. If you update your code with your attempts and have specific questions about why something is not working, or how it is working, it will be easier for people to guide you.

Merging state usually just means copying what you have (…state) and adding what you want to change or add after the copy. The Redux docs have examples and if you use the Redux toolkit it uses immerjs so you can just “mutate” state (there is no actual mutation going on).

Auth is usage and implementation-specific. I’m not sure how your question specifically relates to Redux (other than where you keep the state and how you interact with it).

Anyway, I’m off to eat some food, maybe someone else can give you a better answer.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.