import React, { useState, ReactElement, useRef } from "react"; import { createRoot } from "react-dom/client"; import IntlTelInput from "../src/intl-tel-input/reactWithUtils"; const errorMap = [ "Invalid number", "Invalid country code", "Too short", "Too long", "Invalid number", ]; const App = (): ReactElement => { const ref = useRef(null); const [isValid, setIsValid] = useState(null); const [number, setNumber] = useState(null); const [errorCode, setErrorCode] = useState(null); const [notice, setNotice] = useState(null); const handleSetNumber = (): void => { ref.current?.getInstance().setNumber("+14155552671"); }; const handleSubmit = (): void => { if (isValid) { setNotice(`Valid number: ${number}`); } else { const errorMessage = errorMap[errorCode || 0] || "Invalid number"; setNotice(`Error: ${errorMessage}`); } }; return (
{notice &&
{notice}
} ); }; const container = document.getElementById("app"); if (container) { const root = createRoot(container); root.render(); }