简体   繁体   English

如何将Redux添加到使用Create-React-App创建的React项目中?

[英]How should I add Redux to a React project created with Create-React-App?

I created a React project with Create-React-App. 我用Create-React-App创建了一个React项目。 The package.json file shows: package.json文件显示:

{
  "name": "dashboard",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^15.5.4",
    "react-dom": "^15.5.4"
  },
  "devDependencies": {
    "react-scripts": "1.0.7"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

How do I add Redux? 如何添加Redux? What command do I run to install it into my node_modules? 我运行什么命令将其安装到我的node_modules中?

The npm command to add redux is: 添加redux的npm命令为:

npm install --save redux

This will modify your package.json file by adding redux as a dependency and download the package to your node_modules directory. 这将通过添加redux作为依赖项来修改package.json文件,并将该包下载到node_modules目录。

Your package.json file will look something like this afterwards: 之后,您的package.json文件将如下所示:

{
  "name": "dashboard",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^15.5.4",
    "react-dom": "^15.5.4",
    "redux": "^3.6.0"
  },
  "devDependencies": {
    "react-scripts": "1.0.7"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

You could also add the line with redux (under dependencies ) yourself. 您还可以自己添加带有redux的行(在dependencies下)。

If you do that, you'll have to run npm install afterwards so that the redux package is added to your node_modules . 如果这样做,则必须随后运行npm install ,以便将redux软件包添加到您的node_modules

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在codepen中运行使用“create-react-app”创建的react项目? - how to run react project created with "create-react-app" in codepen? 如何将 Next.js 应用于使用 create-react-app 创建的 React 项目? - How can I apply Next.js to a React project created with create-react-app? 如何将 Preact 添加到现有的 create-react-app 项目中? - How to add Preact to existing create-react-app project? 如何使用create-react-app创建一个新项目 - how do I create a new project with create-react-app 如何构建一个 create-react-app 项目 - how to structure a create-react-app project 如何将Babel插件添加到create-react-app项目? - How do I add a Babel plugin to a create-react-app project? 如何运行Salesforce中create-react-app创建的React App - How to run React App created by create-react-app in Salesforce 如何为使用 create-react-app 创建的 react 项目更新 webpack 配置? - How to update webpack config for a react project created using create-react-app? 如何编写在项目创建的 create-react-app 的单页反应路由器上工作的 JS - How to write JS which working on single page of react router at project created create-react-app 我应该将前端服务器代码放在使用 create-react-app 创建的应用程序中的什么位置? - Where should I put the frontend server code in app created with create-react-app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM