[英]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.