Giter VIP home page Giter VIP logo

nextjs-13-state-management's People

Contributors

mehmetpekcan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

nextjs-13-state-management's Issues

Using global store object causes data leak (redux example)

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.

Problem in app router

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.