React.FC<>是react在typescript中使用的一个泛型,FC即是Function Component的缩写,是函数组件,这个泛型里面可以使用useState。
import React, { useState } from 'react';
export interface NoticeProps {
name: string;
address: string
}
const Notice: React.FC<NoticeProps> = (props) => {
const [ name, setName ] = useState('angle');
const [ count, setCount ] = useState(1);
const addCount=()=>{
setCount(count+1)
}
console.log(count)
return <div>
<p>我是message页面,name是:{name}</p>
<p>我是message页面,count是:{count}</p>
<button onClick={() => setName('jane')}>点击我改变name</button>
<br />
<button onClick={addCount}>点击我改变count</button>
</div>;
}
export default Notice;