创建项目并启动
npm i -g create-react-app
create-react-app hello-world
cd hello-world
npm start
目录结构
关键文件
index.html 文件
index.js 文件
React.StrictMode:检查组件中不合理的代码,可不用
reportWebVitals:性能检测,可不用
App.js 文件
自定义组件
目录结构
- 建议存放于 src/components/组件名/index.jsx
- 引入 js、jsx 时可省略后缀
- 引入目录时默认为引入目录下的 index.js 或 index.jsx
样式模块化
- CSS 样式
- .css 前加入 .module
- 引入成对象,在 jsx 中使用
- 不使用这种方法,而是编写 Less 样式
vscode 插件
ES7+ React/Redux/React-Native snippets