diff --git a/src/modules/GroupChannel/context/GroupChannelProvider.tsx b/src/modules/GroupChannel/context/GroupChannelProvider.tsx index 84649688e..05f049b5e 100644 --- a/src/modules/GroupChannel/context/GroupChannelProvider.tsx +++ b/src/modules/GroupChannel/context/GroupChannelProvider.tsx @@ -33,7 +33,7 @@ import useSendbird from '../../../lib/Sendbird/context/hooks/useSendbird'; import useDeepCompareEffect from '../../../hooks/useDeepCompareEffect'; import { deleteNullish } from '../../../utils/utils'; -const initialState = { +const initialState = () => ({ currentChannel: null, channelUrl: '', fetchChannelError: null, @@ -60,12 +60,12 @@ const initialState = { disableMarkAsRead: false, scrollBehavior: 'auto', scrollPubSub: null, -} as GroupChannelState; +} as GroupChannelState); export const GroupChannelContext = createContext> | null>(null); const createGroupChannelStore = (props?: Partial) => createStore({ - ...initialState, + ...initialState(), ...props, }); @@ -378,7 +378,7 @@ const GroupChannelProvider: React.FC = (props) => { * @returns {ReturnType>} */ const useGroupChannelStore = () => { - return useStore(GroupChannelContext, state => state, initialState); + return useStore(GroupChannelContext, state => state, initialState()); }; // Keep this function for backward compatibility. diff --git a/src/modules/GroupChannelList/context/GroupChannelListProvider.tsx b/src/modules/GroupChannelList/context/GroupChannelListProvider.tsx index f89923387..e4b24b271 100644 --- a/src/modules/GroupChannelList/context/GroupChannelListProvider.tsx +++ b/src/modules/GroupChannelList/context/GroupChannelListProvider.tsx @@ -62,7 +62,7 @@ export const GroupChannelListContext = React.createContext ({ className: '', selectedChannelUrl: '', disableAutoSelect: false, @@ -82,13 +82,13 @@ const initialState: GroupChannelListState = { refresh: null, loadMore: null, scrollRef: { current: null }, -}; +} as GroupChannelListState); /** * @returns {ReturnType>} */ export const useGroupChannelListStore = () => { - return useStore(GroupChannelListContext, state => state, initialState); + return useStore(GroupChannelListContext, state => state, initialState()); }; export const GroupChannelListManager: React.FC = ({ @@ -229,7 +229,7 @@ export const GroupChannelListManager: React.FC = }; const createGroupChannelListStore = (props?: Partial) => createStore({ - ...initialState, + ...initialState(), ...props, }); diff --git a/src/modules/Thread/context/ThreadProvider.tsx b/src/modules/Thread/context/ThreadProvider.tsx index 8833a5075..57455c5e9 100644 --- a/src/modules/Thread/context/ThreadProvider.tsx +++ b/src/modules/Thread/context/ThreadProvider.tsx @@ -59,7 +59,7 @@ export interface ThreadState extends ThreadProviderProps { nicknamesMap: Map; } -const initialState: ThreadState = { +const initialState = () => ({ channelUrl: '', message: null, onHeaderActionClick: undefined, @@ -86,12 +86,12 @@ const initialState: ThreadState = { currentUserId: '', typingMembers: [], nicknamesMap: null, -}; +} as ThreadState); export const ThreadContext = React.createContext> | null>(null); const createThreadStore = (props?: Partial) => createStore({ - ...initialState, + ...initialState(), ...props, }); @@ -248,5 +248,5 @@ export const useThreadContext = () => { }; const useThreadStore = () => { - return useStore(ThreadContext, state => state, initialState); + return useStore(ThreadContext, state => state, initialState()); };