使用Redux避免再次拉数据,除非API数据已经更改



我正在制作一个React Native应用程序,我使用Redux从API中提取数据。现在,我只是想让组件重新渲染时,API数据的变化。如果API数据与之前相同,则不应更改。我如何使用Redux实现这一点?

我已经成功地使用了useSelector钩:

https://react-redux.js.org/api/hooks useselector

使用来自API的数据更新redux存储。当你的redux存储中的数据发生变化时,钩子就会被触发,当你的redux存储发生变化时,任何组件都可以被重新渲染。

import { useSelector } from 'react-redux';
const MyComponent = () => {
const apiData = useSelector(state => state.apiDataLocation);
/*This will update to display the api data whenever the 
store is updated.*/ 
return (
<View>
<Text>{apiData}</Text>
</View>
);
};

最新更新