react——项目搭建(引入 typescript)、基础数据事件传输绑定(TodoList)

本文档介绍了如何创建一个React项目并引入TypeScript。首先,详细讲述了如何配置创建带有SCSS支持和公共样式的React项目。接着,通过两种方式指导如何在已有的React项目中集成TypeScript,包括直接构建TypeScript项目和修改tsconfig.json配置。最后,讨论了React中的基础数据事件传输绑定,这对于理解React应用的数据流动至关重要。
摘要由CSDN通过智能技术生成

创建 react 项目

cnpm i -g create-react-app
create-react-app my-app

cd my-app

yarn start
#    Starts the development server.
yarn build
#    Bundles the app into static files for production.
yarn test
#    Starts the test runner.
yarn eject
#    Removes this tool and copies build dependencies, configuration files
#    and scripts into the app directory. If you do this, you can’t go back!

如果用 scss,并且配置公共样式

yarn add node-sass sass-resources-loader
module: {
   
  rules: [
    // Apply loader
    {
   
      test: /\.scss$/,
      use: [
        'style-loader',
        'css-loader',
        'postcss-loader',
        'sass-loader',
        {
   
          loader: 'sass-resources-loader',
          options: {
   
            // Provide path to the file with resources
            resources: './path/to/resources.scss',
 
            // Or array of paths
            resources: ['./path/to/vars.scss', './path/to/mixins.scss']
          },
        },
      ],
    },
  ],
},

引入 typescript

一、首次安装create-react-app(如果之前安装过可以跳过这一步)

yarn global add create-react-app或者npm install -g create-react-app

二、 使用create-react-app构建TypeScript项目

create-react-app demo02 --typescript

三、已构建react项目引入TypeScript

npm install --save typescript @types/node @types/react @types/react-dom @types/jest

或者

yarn add typescript @types/node @types/react @ty
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值