我正在使用redux saga来获取数据。但它会一遍又一遍地渲染。我不知道是什么问题 这是我的组件:
const Farms = props => {
useEffect(() => {
props.listFarms();
}, []);
console.log(" [ FARMS ] let see that works :", props.farms);
return (
<div> </div>
);
};
const mapStateToProps = state => {
return {
farms: state.farms
}
};
const mapDispatchToProps ={ listFarms }
export default connect(mapStateToProps, mapDispatchToProps)(Farms);
这是我的传奇发生器:
function* getAllFarms () {
try {
console.log(' [ farms saga ] all farms');
const allFarms = yield call(getFarmsAsync);
yield put(listFarms(allFarms.data))
} catch (error) {
console.log(' [ farms saga ] ERROR');
}
}