zoukankan      html  css  js  c++  java
  • React小记

    1、React Component 一定要大写开头

    在JSX中,小写标签名称被认为是HTML标签。但是,带小点(属性访问器)的小写标签名不是。

    查看HTML标记与React组件

    • <component />编译为React.createElement('component')(html标签)
    • <Component /> 编译 React.createElement(Component)
    • <obj.component /> 编译 React.createElement(obj.component)

    2、type

    type someType = string;

    上面的含义是:someType与string等价,string类型有了另一个名字,那么定义以后怎么用呢?

    let a: someType = 'Tim';

    3、便捷的枚举类型写法

    const arr = ['a', 'b', 'c'] as const;
    
    type ABC = typeof arr[number];
    
    // 等价于
    type ABC = 'a' | 'b' | 'c'

    4、需要规定对象每个value都是同一个类型时

    const keys = ['zhang', 'a', 'mie'] as const;
    
    type keysType = typeof keys[number];
    interface Item {
        name: string;
        price: number;
    }
    
    const itemMap: {[key in keysType]: Item} = {
        zhang: {
            name: 'aaaa',
            price: 123
        }
    }
  • 相关阅读:
    百度--买帽子
    网易--双核处理器
    京东--通过考试
    简单错误记录
    链表中的倒数第k个结点
    数值的整数次方
    二进制中1的个数
    TCP 三次握手
    旋转数组的最小数字
    用两个栈实现队列
  • 原文地址:https://www.cnblogs.com/amiezhang/p/react.html
Copyright © 2011-2022 走看看