markdown 反应数格式器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 反应数格式器相关的知识,希望对你有一定的参考价值。

### Custom input problem
Problem: when using custom input component, I can't pass other custom props with it
```
import TextField from '@material-ui/core/TextField';
...
<NumberFormat format="###-####-####" mask="_"
customInput={TextField}
  label: "전화번호" />
```
this throws error. which is different behavior from official [doc](https://github.com/s-yadav/react-number-format#custom-inputs)  

Workaround: [ref](https://github.com/s-yadav/react-number-format/issues/295#issuecomment-476398044)
```
import React from 'react';
import { default as NumberFormat } from 'react-number-format';
import TextField from '@material-ui/core/TextField';

//@ts-ignore
const CustomInput = ({ customInputProps, ...inputProps }) => {
  return (
    <TextField {...customInputProps} {...inputProps} />
  )
}

class FormattedInputs extends React.Component<{}> {
  render() {
    return (
      //@ts-ignore
      <NumberFormat format="###-####-####" mask="_"
        customInput={CustomInput}
        customInputProps={{
          label: "전화번호"
        }} />
    );
  }
}

export default FormattedInputs
```
### basic: with material-ui
```tsx
class FormattedInputs extends React.Component<Props> {
  state = { value: '' }

  static getDerivedStateFromProps(nextProps: Props) {
    return {
      value: nextProps.value,
    }
  }

  render() {
    return (
      //@ts-ignore
      <NumberFormat format="###-####-####" mask="_"
        value={this.state.value}
        customInput={CustomInput}
        customInputProps={{
          label: "전화번호",
          variant: textFieldVariant,
          margin: textFieldMargin
        }}
        onValueChange={(values) => {
          const { formattedValue, value } = values;
          this.setState({ value })
        }}
      />
    );
  }
}

export default FormattedInputs
```

以上是关于markdown 反应数格式器的主要内容,如果未能解决你的问题,请参考以下文章

使用Chrome浏览器作为Markdown渲染器--最优雅的Markdown预览方案

Markdown 元数据格式

HyperDown.js 这个markdown解析器在浏览器中怎么使用

Hexo选择更高级的Markdown渲染器

日期格式化器 24 小时制,两位数

markdown Vue反应系统