Unform
Simple input
Simple input
Simple input with Unform, all of your input sources must be created by you.
Here we have an example of a very simple input with support for label and error.
components/Input.js
1import React, { useRef, useEffect } from 'react';2import { useField } from '@unform/core';34export default function Input({ name, label, ...rest }) {5 const inputRef = useRef(null);67 const { fieldName, defaultValue, registerField, error } = useField(name);89 useEffect(() => {10 registerField({11 name: fieldName,12 ref: inputRef.current,13 path: 'value',14 });15 }, [fieldName, registerField]);1617 return (18 <>19 <label htmlFor={fieldName}>{label}</label>2021 <input22 id={fieldName}23 ref={inputRef}24 defaultValue={defaultValue}25 {...rest}26 />2728 {error && <span className="error">{error}</span>}29 </>30 );31}