in the model file
import { articleDetail } from "../../service/api";
export default {
namespace: "article",
state: {
detail: null
},
reducers: {
saveDetail(state, { payload }) {
return {
...state,
detail: payload
};
}
},
effects: {
*articleDetail({ payload: threadId }, { call, put }) {
const res = yield call(articleDetail, threadId);
if (res.code === 200) {
yield put({
type: "saveDetail",
payload: res.data
});
}
},
}
}
in the component
import React from "react";
import { connect } from "dva";
function ArticleDetail({ match, dispatch }) {
dispatch({
type: "article/articleDetail",
payload: match.params.id
});
return (
<div>detail/{match.params.id}</div>
);
}
export default connect(({ article }) => ({ article }))(ArticleDetail);
how to get a request correctly in a stateless component