大家好,我对您更喜欢哪种方法有疑问:
在带有 TypeScript 的 React 功能组件中,使用 useSelector 从 Redux State 获取值是:1)
const campaign = useSelector(campaignSelector);
const [audienceSample, setAudienceSample] = useState<number | null>((campaign ||
{max_completes_total: null})['max_completes_total']);
来自 2)
const campaign = useSelector(campaignSelector);
const [audienceSample, setAudienceSample] = useState<number | null>(null);
useEffect(() => {
setAudienceSample(campaign.max_completes_total)
},[campaign])
我知道 1 是更少的代码,但你认为它更快吗,你更喜欢哪一个,谢谢你们