Mutate state based on existing fields

≯℡__Kan透↙ 提交于 2019-12-11 07:33:21

问题


With React-Final-Form, I am creating a control that allows users to be listed ina directory if a radio button is clicked. In the click handler, I wish to auto-populate a textbox with the user's first and last names. I am doing this with a mutator, and I'm hoping I can get confirmation that I am doing this correctly, as I couldn't find documentation about the lastFieldState property I'm leveraging:

  setDisplayName: (args, state, utils) => {
  const { firstname, lastname } = state.fields;
  const currentFirstName = firstname.lastFieldState.value;
  const currentLastName = lastname.lastFieldState.value;
  utils.changeValue(state, 'displayName', () => `${currentFirstName} ${currentLastName}`);
},

回答1:


Author of the library here. I can confirm that you are doing things just fine. 👍



来源:https://stackoverflow.com/questions/51026497/mutate-state-based-on-existing-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!