Passe apenas números na entrada reagir js

import React, { useState } from "react";

export default function App() {
  const [val, setVal] = useState(0);

  return (
    <div>
      <input
        type="text"
        pattern="[0-9]*" //set pattern
        value={val}
        onChange={(e) =>
          setVal((v) => (e.target.validity.valid ? e.target.value : v)) //check if the pattern equals to the value
        }
      />
    </div>
  );
}
Fen Fenovich