javascript - 轻松设置 react redux with next.js (React)

我看过使用 redux 的 next.js 示例。但是有什么简单的方法可以用 next.js 设置 redux 吗? 我想设置 redux 我以前用 react.js 设置的方式

最佳答案

假设您了解 Redux 和 React。

首先,安装这些包

$ npm install next-redux-wrapper react-redux redux redux-thunk --save

$ npm install redux-devtools-extension --save-dev


覆盖或创建默认App,创建文件./pages/_app.js如下图:

import withRedux from 'next-redux-wrapper'
import { Provider } from 'react-redux'
import { withRouter } from 'next/router'
import App from 'next/app'

import createStore from 'store/createStore'

class MyApp extends App {
  render () {
    const { Component, pageProps, router, store } = this.props
    return (
          <Provider store={store}>
              <Component router={router} {...pageProps} />
          </Provider>
    )
  }
}

export default withRedux(createStore)(
  withRouter(MyApp)
)

在您的页面/组件中,您可以像往常一样使用 Redux。

https://stackoverflow.com/questions/65421030/

相关文章:

python - 从 python 列表创建子列表

python - , 运算符用在条件语句的右侧时有何作用?

python - 将 dict 值设置为自身会创建无限副本

firebase - Flutter Firestore 离线数据库

windows - 使 HTML 不适用于 Windows 10 中的 Sphinx 文档

python - 根据所选列过滤重复的行并与 Pandas 中的另一个数据框进行比较

python - 从多列的 value_counts 中排除项目

r - 如何使用 dplyr 在 R 中转置数据帧?

r - 如何检查 data.table 各行中的值是否相同

amazon-web-services - Amazon RDS 和 VPC 端点连接