React Hook React.useEffect 缺少依赖项:'params.id'。要么包含它,要么移除依赖数组 react-hooks/exhaustive-deps。我项目中的很多地方都出现了这个错误。
import React, { Fragment } from "react";
import ArticleDetails from "./List";
import { connect } from "react-redux";
import {
articleFetchById,
articleFetch,
articleFetchByChannel
} from "../../../redux/action/articles";
const Article = ({
articles,
articleFetchById,
match: { params },
auth,
articleFetch,
articleFetchByChannel
}) => {
React.useEffect(() => {
articleFetchById(params.id);
}, [articleFetchById]);
React.useEffect(() => {
articleFetch();
}, [articleFetch]);
React.useEffect(() => {
articleFetchByChannel();
}, [articleFetchByChannel]);
return (
<Fragment>
<ArticleDetails articles={articles} auth={auth} matchId={params.id} />
</Fragment>
);
};
const mapStateToProps = state => {
return {
articles: state.articles,
auth: state.auth
};
};
export default connect(mapStateToProps, {
articleFetchById,
articleFetch,
articleFetchByChannel
})(Article);