I'm just play around with typescript and I've got problem to use useRef in a custom element
passing it as prop
I've tried with
import React from "react";
export interface InputProps
extends React.InputHTMLAttributes<HTMLInputElement> {
ref: HTMLElement | null
}
const Input: React.FC<InputProps> = ({ ...inputProps }) => {
return (
<input
className="px-2 py-1 text-gray-700 text-2xl bg-white border-2 border-gray-200 hover:border-purple-300 focus:outline-none focus:bg-white rounded-l-lg shadow-md"
{...inputProps}
/>
);
};
export default Input;
import React, { useRef } from "react";
import Input from "./input";
import Button from "./button";
const Form: React.FC = () => {
const todoRef = useRef<HTMLElement | null>(null);
return (
<form onSubmit={}>
<Input type="text" id="todo" ref={todoRef}/>
<Button type="submit">+</Button>
</form>
);
};
export default Form;
What's the right way, please?
UPDATE
I worked out with: https://codesandbox.io/s/typescript-useref-example-e0hc4