简体   繁体   中英

Is it really required to use 'next-redux-wrapper' in a 'Next.js + Redux Toolkit' application when doing only 'static generation'?

I'm planning to create a Next.js application along with Redux Toolkit for state management. I'll only be doing Static Generation (using getStaticProps & getStaticPaths ).

Do I need to use next-redux-wrapper ( https://github.com/kirill-konshin/next-redux-wrapper ) ?

Can I get all the benefits of static generation without using next-redux-wrapper ?

Short answer is — it's not required, but it makes things more convenient. Even for static.

I would say that if you need only static generation, adding Redux will make your life much harder. Since getStaticProps (as well as getServerSideProps ) is done on the server, every page navigation will result in the new redux store, that would be quite painful to properly hydrate with the already existent client side state.

Redux is only good when you initialise it once with the classical getInitialProp and then only work with in on the client side.

If you still have a lot of client side state management in useEffect , having Redux could make sense, but read carefully the hydration part of the next-redux-wrapper doc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM