Open iBasit opened 6 years ago
Please put this in a CodePen or CodeSandbox. It's the only way I can properly test it.
Do you have any CodePen actions.merge
or action.contact
examples, maybe I can see the demo and see if I'm doing anything wrong.
Hello! I have the same problem with actions.merge
...
Hello! As for me, I solved this problem. I used a Redux action generator actions.merge. At first, It didn't work because I tried to invoke it from the child component. But I should have done it in the MainComponent.js file in the componentDidUpdate hook.
In the ActionCreators.js I declared:
import actions from 'react-redux-form';
. . .
export const setDefaultFormValues = (values) => (dispatch) => {
dispatch(setDefaultUser: (values) => actions.merge(‘editTask’, values));
}
Then in the MainComponent.js I wrote:
. . .
import { setDefaultValues } from '../redux/ActionCreators';
const mapDispatchToProps = dispatch => ({
. . .
setDefaultValues: (values) => dispatch(setDefaultValues(values))
});
componentDidUpdate() {
let pathname = this.props.location.pathname;
let pos = pathname.search("/edit/") + 6;
let taskId = pathname.substring(pos, pathname.length);
if (taskId) {
let tasks = this.props.tasks.tasks.tasks;
if (tasks) {
let task = tasks.filter(task => task.id === parseInt(taskId, 10))[0];
if (task) {
this.props.setDefaultValues(task);
}
}
}
}
The Problem
on componentDidMount I want to fetch url parms and overwrite form values. I'm using dispatch with action.merge and I have even tried other methods like action.change and action.load. it does not effect at all.
Steps to Reproduce
my store.js file
Expected Behavior
form values to be overwritten to new values
Actual Behavior
showing the default values