Skip to content

Instantly share code, notes, and snippets.

@marlosirapuan
Last active May 1, 2019 22:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marlosirapuan/722ba3883a7bea35084f3aff3164c0f3 to your computer and use it in GitHub Desktop.
Save marlosirapuan/722ba3883a7bea35084f3aff3164c0f3 to your computer and use it in GitHub Desktop.
Ant Design with InputMask

Based on this comment

Fix warning when use react-hooks:
Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?

// shared/InputMask.js

import { Input } from 'antd'
import React, { forwardRef } from 'react'
import ReactInputMask from 'react-input-mask'
import PropTypes from 'prop-types'

const InputMask = forwardRef((props, ref) => {
  return (
    <ReactInputMask {...props}>
      {(inputProps) => <Input {...inputProps} ref={ref} disabled={props.disabled ? props.disabled : null} />}
    </ReactInputMask>
  )
})

InputMask.propTypes = {
  mask: PropTypes.string,
  maskChar: PropTypes.string,
  formatChars: PropTypes.object,
  alwaysShowMask: PropTypes.bool,
  inputRef: PropTypes.func
}

export default InputMask
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment