팀원분이랑 같이 밤새면서 프로젝트 하는데 css가 잘 안돼서 ㅋㅋㅋㅋ 닉네임 길이가 길어지면 동석이 형님 얼굴이 점점 찌그러드는게 너무 웃겨서 한참 웃었다🤣
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
import { request } from '../../utils/Api';
const initialState = {
search: [],
loading: false,
error: null,
nextPageToken: null,
};
interface VideoPayload {
channelId: string;
orderType?: string;
results?: number;
}
export const getSearchVideos = createAsyncThunk(
'getSearchVideos',
async ({ channelId, orderType, results }: VideoPayload, thunkAPI) => {
try {
const { data } = await request('/search', {
params: {
part: 'snippet',
channelId: channelId,
order: orderType ?? 'date',
maxResults: results ?? 50,
pageToken: '',
type: 'video',
},
});
return thunkAPI.fulfillWithValue(data);
} catch (error) {
return thunkAPI.rejectWithValue(error);
}
},
);
const mediaSlice = createSlice({
name: 'media',
initialState,
reducers: {},
extraReducers: (builder) => {
builder.addCase(getSearchVideos.fulfilled, (state, { payload }) => {
state.search = payload.items;
state.nextPageToken = payload.nextPageToken;
});
},
});
export default mediaSlice.reducer;
import { configureStore } from '@reduxjs/toolkit';
import media from '../modules/MediaSlice';
import artists from '../modules/ArtistsSlice';
const store = configureStore({
reducer: {
media,
artists,
},
});
export default store;
// State의 타입 얻기
export type RootState = ReturnType<typeof store.getState>;
// Dispatch 타입 얻기
export type AppDispatch = typeof store.dispatch;