Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/modules/GroupChannel/context/GroupChannelProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -60,12 +60,12 @@ const initialState = {
disableMarkAsRead: false,
scrollBehavior: 'auto',
scrollPubSub: null,
} as GroupChannelState;
} as GroupChannelState);

export const GroupChannelContext = createContext<ReturnType<typeof createStore<GroupChannelState>> | null>(null);

const createGroupChannelStore = (props?: Partial<GroupChannelState>) => createStore({
...initialState,
...initialState(),
...props,
});

Expand Down Expand Up @@ -378,7 +378,7 @@ const GroupChannelProvider: React.FC<GroupChannelProviderProps> = (props) => {
* @returns {ReturnType<typeof createStore<GroupChannelState>>}
*/
const useGroupChannelStore = () => {
return useStore(GroupChannelContext, state => state, initialState);
return useStore(GroupChannelContext, state => state, initialState());
};

// Keep this function for backward compatibility.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const GroupChannelListContext = React.createContext<ReturnType<typeof cre
export interface GroupChannelListState extends GroupChannelListContextType {
}

const initialState: GroupChannelListState = {
const initialState = () => ({
className: '',
selectedChannelUrl: '',
disableAutoSelect: false,
Expand All @@ -82,13 +82,13 @@ const initialState: GroupChannelListState = {
refresh: null,
loadMore: null,
scrollRef: { current: null },
};
} as GroupChannelListState);

/**
* @returns {ReturnType<typeof createStore<GroupChannelListState>>}
*/
export const useGroupChannelListStore = () => {
return useStore(GroupChannelListContext, state => state, initialState);
return useStore(GroupChannelListContext, state => state, initialState());
};

export const GroupChannelListManager: React.FC<GroupChannelListProviderProps> = ({
Expand Down Expand Up @@ -229,7 +229,7 @@ export const GroupChannelListManager: React.FC<GroupChannelListProviderProps> =
};

const createGroupChannelListStore = (props?: Partial<GroupChannelListState>) => createStore({
...initialState,
...initialState(),
...props,
});

Expand Down
8 changes: 4 additions & 4 deletions src/modules/Thread/context/ThreadProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export interface ThreadState extends ThreadProviderProps {
nicknamesMap: Map<string, string>;
}

const initialState: ThreadState = {
const initialState = () => ({
channelUrl: '',
message: null,
onHeaderActionClick: undefined,
Expand All @@ -86,12 +86,12 @@ const initialState: ThreadState = {
currentUserId: '',
typingMembers: [],
nicknamesMap: null,
};
} as ThreadState);

export const ThreadContext = React.createContext<ReturnType<typeof createStore<ThreadState>> | null>(null);

const createThreadStore = (props?: Partial<ThreadState>) => createStore({
...initialState,
...initialState(),
...props,
});

Expand Down Expand Up @@ -248,5 +248,5 @@ export const useThreadContext = () => {
};

const useThreadStore = () => {
return useStore(ThreadContext, state => state, initialState);
return useStore(ThreadContext, state => state, initialState());
};