React - How to export a pure stateless component

前端 未结 4 1268
臣服心动
臣服心动 2021-01-31 00:58

How can I export a stateless pure dumb component?

If I use class this works:

import React, { Component } from \'react\';

export default class Header ext         


        
4条回答
  •  情歌与酒
    2021-01-31 01:44

    you can do it in two ways

    const ComponentA = props => {
      return 
    {props.header}
    ; }; export default ComponentA;

    2)

    export const ComponentA = props => {
      return 
    {props.header}
    ; };

    if we use default we import like this

    import ComponentA from '../shared/componentA'
    

    if we don't use default we import like this

    import { ComponentA } from '../shared/componentA'
    

提交回复
热议问题