React注册一个组件

class组件

注册组件
import React,{Component} from 'react';

class Content extends Component {
    render() {
        return (
            <div className="">
                今天是{parseInt(Math.random()*31)}</div>
        )
    }
}

export default Content;
比如说在App组件里引用此组件,如下
import React from 'react';
// import logo from './logo.svg';
import './App.css';
import Content from './component/content';

function App() {
  return (
    <div className="App">
      <Content></Content>
      <Content></Content>
    </div>
  );
}

export default App;

普通函数组件

import React from 'react';

let Content = function () {
    return(
        <div>
            今天是{parseInt(Math.random()*31)}</div>
    )
}

export default Content;

猜你喜欢

转载自blog.csdn.net/weixin_45679977/article/details/104547442
今日推荐