DEV Community

Discussion on: Advanced Blazor State Management Using Fluxor, part 5 - ASP.NET EditForm Binding

Collapse
mrpmorris profile image
Peter Morris

My approach is to allow the user to edit the DTO that is sent to the API.

When the form is submitted, I Dispatch an action containing that DTO.
A Reducer sets IsSaving = true
An effect calls the server
If the server indicates success then I dispatch a different action with the DTO in it
Any state that has an interest in that piece of data (e.g. Client) has a reducer that reduces the values of the DTO properties into their own immutable states.

You should avoid having mutable state.

Collapse
mr_eking profile image
Eric King Author

Yes, I'm doing exactly the same thing, with the one exception that I'm also storing the form's DTO (which I'm calling "model" above) into the form component's state.

I feel that's ok, since there's no chance for the state of that form's DTO to have any effect on anything else in the application's state. Not other features' states, not even its own feature's state. It merely allows the form's field values a place to live.

If there were something other than the data-bound form itself that has interest in the DTO properties then they would have to get that value via a reducer like everything else.