Rename custom hook

This commit is contained in:
Joao Victor 2022-05-30 15:49:19 -03:00
parent 1143cb87c7
commit 65b59a6062
2 changed files with 10 additions and 4 deletions

View File

@ -9,7 +9,7 @@ import ChatPushAlert from './push-alert/component';
import { stripTags, unescapeHtml } from '/imports/utils/string-utils';
import Service from '../service';
import Styled from './styles';
import { usePrevious } from '/imports/ui/components/utils/hooks';
import { usePreviousValue } from '/imports/ui/components/utils/hooks';
const CHAT_CONFIG = Meteor.settings.public.chat;
const PUBLIC_CHAT_CLEAR = CHAT_CONFIG.chat_clear;
@ -76,7 +76,7 @@ const ChatAlert = (props) => {
const [unreadMessages, setUnreadMessages] = useState([]);
const [lastAlertTimestampByChat, setLastAlertTimestampByChat] = useState({});
const [alertEnabledTimestamp, setAlertEnabledTimestamp] = useState(null);
const prevUnreadMessages = usePrevious(unreadMessages);
const prevUnreadMessages = usePreviousValue(unreadMessages);
// audio alerts
useEffect(() => {

View File

@ -1,6 +1,12 @@
import { useEffect, useRef } from 'react';
export const usePrevious = (value) => {
/**
* Custom hook to get previous value. It can be used,
* for example, to get previous props or state.
* @param {*} value
* @returns The previous value.
*/
export const usePreviousValue = (value) => {
const ref = useRef();
useEffect(() => {
ref.current = value;
@ -9,5 +15,5 @@ export const usePrevious = (value) => {
}
export default {
usePrevious,
usePreviousValue,
};