Skip to content

Instantly share code, notes, and snippets.

@danileao
Created June 26, 2020 18:30
Show Gist options
  • Save danileao/c33f56f687514806f6e118d510ca59ab to your computer and use it in GitHub Desktop.
Save danileao/c33f56f687514806f6e118d510ca59ab to your computer and use it in GitHub Desktop.
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