markdown 打字稿tsx
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 打字稿tsx相关的知识,希望对你有一定的参考价值。
[cheat sheet](https://github.com/sw-yx/react-typescript-cheatsheet/blob/master/README.md)
# Functional Component
```tsx
const MobxWrapper: React.FunctionComponent<{ children: any }> = ({ children }) => {
return (<div>
<Provider {...stores}>
<div>
<DevTools />
{children}
</div>
</Provider>
</div>)
}
```
# Stateful Component
```tsx
import React from 'react'
interface IProps {
text: string;
age?: number;
}
interface IState {
email: string;
name: string;
}
export default class Form extends React.Component<IProps, IState>{
state = {
email: "",
name: ""
}
handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const { name, value } = e.target
this.setState({
name: value
});
}
render() {
const { text } = this.props
const { name } = this.state
return (
<div>
<div>{text}</div>
<input name="name" value={name} onChange={this.handleChange} />
</div>
)
}
}
```
以上是关于markdown 打字稿tsx的主要内容,如果未能解决你的问题,请参考以下文章