// app/page.tsx (Server) import CounterWrapper from './CounterWrapper'; export default async function Page() { const dataFromDB = await fetchSomeData(); // Server-side fetch return <CounterWrapper initialData={dataFromDB} />; }
const counterSlice = createSlice({ name: 'counter', initialState, reducers: { increment: (state) => { state.value += 1; }, decrement: (state) => { state.value -= 1; }, setValue: (state, action: PayloadAction<number>) => { state.value = action.payload; }, }, }); the complete guide 2024 incl nextjs redux free download new
npm install redux-persist Create your store inside lib/redux/ . // app/page
npx create-next-app@latest my-redux-app --typescript --tailwind --app cd my-redux-app Now, install the required Redux packages (versions compatible with Next.js 14): useGetPostByIdQuery } = apiSlice
import { configureStore } from '@reduxjs/toolkit'; import counterReducer from './features/counterSlice'; import { apiSlice } from './features/apiSlice'; export const makeStore = () => { return configureStore({ reducer: { counter: counterReducer, [apiSlice.reducerPath]: apiSlice.reducer, }, middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(apiSlice.middleware), }); };
RTK Query automatically caches, dedupes, and refetches on window focus. No extra code needed. 8. Global State Persistence (LocalStorage + Cookies) To persist Redux state across page reloads, use redux-persist with Next.js.
export const { useGetPostsQuery, useGetPostByIdQuery } = apiSlice;
본 사이트에 게시된 모든 사진과 글은 저작권자와 상의없이 이용하거나 타사이트에 게재하는 것을 금지합니다.
사진의 정확한 감상을 위하여 아래의 16단계 그레이 패턴이 모두 구별되도록 모니터를 조정하여 사용하십이오.

Copyright 2007. 출사코리아. All rights reserved.
DESIGN BY www.softgame.kr