React

作者: 曹锦花 | 来源:发表于2020-01-27 16:33 被阅读0次
//创建项目
npx create-react-app react-text

//安装antd
npm install antd --save

//按需加载
npm install react-app-rewired@2.0.2-next.0 babel-plugin-import --save

//高阶组件装饰器安装
npm install --save-dev babel-plugin-transform-decorators-legacy

//配置
   config = injectBabelPlugin(
        ["@babel/plugin-proposal-decorators", { legacy: true }],
        config
    );

//安装redux
npm i redux -S
//安装react-redux 
npm install react-redux --save
//安装redux-thunk / redux-logger 中间件
npm install redux-thunk --save
npm install redux-logger --save
//安装react-router-dom
npm i react-router-dom --S
npm install --save redux-saga

super() / super(props)

子类继承父类的属性:需要使用super()继续父类的属性,同时创建this(子类本身没有this);
super(props)的作用就是在父类的构造函数中给props赋值一个对象this.props=props这样就能在它的下面定义你要用到的属性了,然而其他的由于没有传参就直接赋值为undefind

setState

//批量执行错误使用  只会执行一次
        this.setState({counter: this.state.counter + 1})
        this.setState({counter: this.state.counter + 1})
        this.setState({counter: this.state.counter + 1})
        this.setState({counter: this.state.counter + 1})
//批量执行正确使用
   this.setState(prevState => ({
            counter: prevState.counter + 1
        }));

        this.setState(prevState => ({
            counter: prevState.counter + 1
        }));

        this.setState(prevState => ({
            counter: prevState.counter + 1
        }));
//可接收参数
         // this.setState(obj, callback)
        // this.setState(fn, callback)

相关文章

  • React基础

    react 教程 react 组件介绍 react state 介绍 react Props 介绍 React:组...

  • 学习react no.1

    学习react no.1 react 定义 react 特点 react

  • React Native 学习之路

    React 相关资料 React Components React Properties React State ...

  • React基础

    React包含react元素和react组件 react元素 react组件 react组件分为函数组件和类组件 ...

  • React面试题 整理脑图

    react基础 React生命周期 react-router react进阶 react Hooks redux 其他

  • react 导入中的 as

    import React from 'react'只导入 是 React。 而import * as React ...

  • ES5与ES6小结部分

    1var React=require('react'); 等价 import React from ' react...

  • React DnD基础概念和整体架构

    React DnD 的英文是 Drag and Drop for React。React DnD 是 React ...

  • React

    React 《React 官网文档》 React简介 React概念 React官网学习实践 - jSX简介 Re...

  • React学习笔记_01

    React 基础组件 react概述 npm i react react-dom react包 是核心,提供创建元...

网友评论

      本文标题:React

      本文链接:https://www.haomeiwen.com/subject/xyhjzctx.html