我有一个用户个人资料页面,用户可以在其中更新数据。提交数据后,应将其重定向到仪表板页面。
我的配置文件
handleProfileUpdate = () => {
let user = this.state;
this.props.updateUserProfile(user);
}
Run Code Online (Sandbox Code Playgroud)
动作定义如下
export const updateUserProfile = (obj) => ({
type: types.USER_PROFILE_UPDATE_REQUEST,
payload: obj
});
Run Code Online (Sandbox Code Playgroud)
Saga 文件定义如下。
function* updateUserProfile(action) {
try {
let data = action.payload;
yield call(userProvider.updateUserProfile, data);
// dispatch a success action to the store
yield put({ type: types.USER_PROFILE_UPDATE_SUCCESS, data });
yield put(push('/dashboard'));
yield put(constants.successMsg(userProfileUpdateSuccess));
} catch (error) {
// dispatch a failure action to the store with the error
yield put(constants.DEFAULT_ERROR_MSG);
}
}
export function* watchUserProfileUpdateRequest() …Run Code Online (Sandbox Code Playgroud) 我有一个具有几个子组件的父组件。为子组件传递的道具都是相同的。例如
<TextQuestion questionInfo={this.props.questionInfo} key={this.props.questionInfo.module_question_id} handleChange={this.handleChange} />
<DropDown questionInfo={this.props.questionInfo} key={this.props.questionInfo.module_question_id} handleChange={this.handleChange} />
<Checkbox questionInfo={this.props.questionInfo} key={this.props.questionInfo.module_question_id} handleChange={this.handleChange} />
Run Code Online (Sandbox Code Playgroud)
有没有更有效的方法可以做到这一点?可能是一个返回道具并被添加到子组件的函数调用?
代码如下
const {
aForm,
bForm,
eForm,
qForm,
} = this.form;
return (
aForm.isEditing ||
bForm.isEditing ||
eForm.isEditing ||
qForm.isEditing
);
Run Code Online (Sandbox Code Playgroud)
有没有办法重构这个?就像是
const forms = pick(this.form, [
"aForm",
"bForm",
"eForm",
"qForm",
]);
Object.values(forms).map(f => f.isEditing).join("||") //Need to return boolean value.
Run Code Online (Sandbox Code Playgroud)