mehmetpekcan / nextjs-13-state-management Goto Github PK
View Code? Open in Web Editor NEWExample repository of state managements alternatives of Next.js 13 App directory
Example repository of state managements alternatives of Next.js 13 App directory
In the redux example, at redux/src/app/layout.jsx, on line 15:
await store.dispatch(fetchUser());
you're performing this data fetching on a global store reference. This can potentially cause data leakage between requests.
To see it in action, first add a console.log before the data fetching:
export default async function RootLayout({ children }) {
console.log(store.getState());
await store.dispatch(fetchUser());
const { user } = store.getState().user;
Now, when you visit a page for the first time (first user), the output is empty as expected:
{
basket: { basket: [] },
products: { product: {}, products: [] },
user: { user: {} }
}
But, if you open another tab (incognito if you will, to keep it even more isolated), the previously fetched data is available, since the store instance is global:
{
basket: { basket: [] },
products: {
product: {},
products: [
[Object], [Object], [Object],
[Object], [Object], [Object],
[Object], [Object], [Object],
[Object], [Object], [Object],
[Object], [Object], [Object],
[Object], [Object], [Object],
[Object], [Object]
]
},
user: { user: { id: 1, name: 'John Doe' } }
}
When done sequentially like this the data will get overwritten so it may seem like it's not a problem, but in a real setup you'll have parallel users which causes race conditions.
when i fetch data from api in app page and try to set in redux it not working i tried and search everywhere bu i dont get solution
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.