redux form with undo
See original GitHub issueHello,
I are really new to react/redux and redux-form so I might have an error in reasoning. Anyway, what I am trying to do is writing my own decorator that should give my redux form an undo functionality. I didn’t want to mess with redux form internal state through reducer.plugin() therefore I defined my own state “undoableForm” which resides at the same level like “form”. My default state looks like this (the entire source code is attached):
const defaultState = {
undoableForm: {
initialValues: {name: 'test'},
currentValues: {name: 'test'},
previousValues: [], //undo
}
}
Every time a CHANGE happens (I listen to redux-form CHANGE event), I save the old value in previousValues and update currentValues. My undoableForm decorator gets the previousValues through connect and upon that it provides “undoable” (true/false) and “undo” (function) to the decorated redux-form. In my form I defined an UndoButton component that gets their new props and gets activated/deactivated whenever “undoable” changes, and by clicking it “undo” should be called.
I have the following problems:
- whenever I change the value in the input-box the whole form gets unmounted/mounted. Every field gets unregistered and then registered again. The problem comes from the fact that I am providing previousValues through connect. But I have to do that since my decorator depends on this to calculate “undoable”.
- I must set destroyOnMount to false otherwise the value in the input-box won’t get updated.
- In my own state “undoableForm” everything seems to be fine but I still don’t know how to update the values in state.form when I click on “undo”-button.
I am not sure whether I am doing something wrong … maybe the structure is wrong or maybe a decorator over redux-form is not the right way to do that. But I am sure that I need your help 😃 Thank you very much in advance!
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
I still think this would be a great addition to RF…
Hi, I had the same problem and came up with this solution.
Prerequisites:
EditableCV.js
EditableCV.js
It looks like this and supports: