Should the status of the modal box in dvajs be placed inside the component or in the model?

use dva to encounter the add function. Here is the form that clicks the add button to display the modal box, but the closing time cannot be judged by the returned result if you use state, in the component (some fields cannot be added when duplicated). Now that the logic of displaying and closing is written into model, is it okay to do so?

part of the code:

component:

function handleAdd() {
   dispatch({ type: "user/saveAddModalVisible", payload: true });
}
function handleCancel() {
   dispatch({ type: "user/saveAddModalVisible", payload: false });
}

<Button onClick={handleAdd}></Button>
<Modal
    title=""
    visible={addModalVisible}
    onCancel={handleCancel}
   >
    <div>
      <Form>
        // ...
      </Form>
    </div>
</Modal>

in model:

*addChannel({ payload }, { call, put }) {
  const res = yield call(addChannelReq, payload);
  if (res.code === 200) {
    yield put({ type: "saveAddModalVisible", payload: false });
    message.success("");
  } else {
    message.destroy();
    message.warning(res.msg);
  }
},
Apr.09,2021

it's OK to write this way.
Let me show you how I usually write it. Learn from each other.
I usually write this way. In model, the state method of modal is written separately

.
 hideModal(state) {
            return { ...state, ModalVisible: false }
        },
 showModal(state) {
            return { ...state, ModalVisible: true }
        },

in this way, you only need to call showModal and hideModal in the component

The model in

dva puts redux's action and reducer together.
more global variables and data are stored in
model. In fact, you don't have to put everything in model.
like modal's visible or other state, used by this component can write state in the component without model,. Instead, the code becomes complicated with model. There is a saying in
redux, when you don't know if you want to use redux. In fact, it is not needed

Menu