extending React.Component vs Component

后端 未结 2 1459
后悔当初
后悔当初 2021-02-05 01:51

I just got in a project on React Native, where I constantly see classes extending both React.Component and Component itself.

Examples:

2条回答
  •  野的像风
    2021-02-05 02:46

    Well you can do whatever you want really.

    Doing import { Component } from 'react' is effectively the same thing as React.Component.

    The import { Component } from 'react' syntax is called a Named Import

    The import statement is used to import bindings which are exported by another module.

    import defaultExport from "module-name";
    import * as name from "module-name";
    import { export } from "module-name";
    import { export as alias } from "module-name";
    import { export1 , export2 } from "module-name";
    import { export1 , export2 as alias2 , [...] } from "module-name";
    import defaultExport, { export [ , [...] ] } from "module-name";
    import defaultExport, * as name from "module-name";
    import "module-name";
    

提交回复
热议问题