Created
June 26, 2020 18:30
-
-
Save danileao/c33f56f687514806f6e118d510ca59ab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useRef, useCallback, useEffect } from "react"; | |
import ReactInputMask from "react-input-mask"; | |
import { useField } from "@unform/core"; | |
export default function InputMaskT({ name, mask, ...rest }) { | |
const inputRef = useRef(null); | |
const { fieldName, registerField, defaultValue, error } = useField(name); | |
console.log(inputRef); | |
function mudar(event) { | |
console.log(event.target.value) | |
inputRef.current.value = event.target.value | |
} | |
useEffect(() => { | |
registerField({ | |
name: fieldName, | |
ref: inputRef.current, | |
path: 'value', | |
}); | |
}, [fieldName, registerField]); | |
return ( | |
<ReactInputMask ref={inputRef} onChange={(event) => mudar(event)} {...rest} /> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment