nova-betterchat/src/hooks/useSaveToLocalStorage.ts

13 lines
315 B
TypeScript
Raw Normal View History

2023-03-03 23:17:11 +01:00
import React, { useEffect } from 'react';
import useStore from '@store/store';
const useSaveToLocalStorage = () => {
const chats = useStore((state) => state.chats);
useEffect(() => {
if (chats) localStorage.setItem('chats', JSON.stringify(chats));
}, [chats]);
};
export default useSaveToLocalStorage;