【发布时间】:2020-01-19 22:47:25
【问题描述】:
这是我的设置:
// store/actions/user.js
export const discoverFollowingStatus = followsId => {
return (dispatch, getState) => {
const userId = getState().user.user.id;
findFollowingFromTo(userId, followsId).then(following => {
dispatch({
type: UPDATE_FOLLOWING_STATUS,
payload: {
followsId,
following: following !== null,
},
});
});
};
};
// component.js
import {
discoverFollowingStatus,
} from '../store/actions/user';
...
useEffect(() => {
discoverFollowingStatus(followedUserId);
console.log(discoverFollowingStatus);
}, [followedUserId, discoverFollowingStatus]);
最大的问题是屏幕不断地重新渲染,因为 useEffect 正在触发。为什么那个导入的常量会改变并触发它?
【问题讨论】:
-
好像
followedUserId或discoverFollowingStatus更新了。所以它会触发discoverFollowingStatus。
标签: javascript ios react-native asynchronous redux