我正在构建一个便笺应用程序。我希望保存用户在本地存储中输入的注释,以便即使在刷新页面之后也可以获得它。本地存储正常工作,但一旦我刷新本地存储中的项目,就会被删除。
const [notes, setNotes] = useState([]);
// This is the state variable that contains all the notes that are entered by the user.
useEffect(() => {
window.localStorage.setItem('react-notes-app-data', JS
在我的react项目中,每当一些reducer状态属性发生变化时,我都会更新数据库。 useEffect(() => {
//Updating db here
}, [reducerState.table, reducerState.order, reducerState.bill, reducerState.liveCart, reducerState.occupency]) 当我重新加载页面时,我需要将其设置为初始状态,所以我使用另一个类似于下面的useEffect useEffect(() => {
//making db call to get the
我检查了堆叠溢出,虽然有类似的问题,但没有一个解决我的问题的诡辩。
我有一个组件,如果它从父元素接收到更新,就会触发useEffect。因此,它调用一个函数来刷新某些组件并加载新的组件。问题是,在执行此函数时,会修改一些元素并再次触发useEffect。我已经尝试过修改useEffect的参数,以便它只刷新某些值,但是它不能正常工作。
错误:
Warning: Maximum update depth exceeded. This can happen when a component calls setState inside useEffect, but useEffect either