4

I am trying to use the phone mark with React, but I am getting the error

Please include phone-type-formatter.{country}.js lib.

This is how I've attempted:

import CleavePhone from "cleave.js/src/addons/phone-type-formatter.i18n"; // and also
import CleavePhone from "cleave.js/dist/addons/cleave-phone.i18n"; // and BOTH
...
<CleavePhone
  name={name}
  value={value}
  className={cx("form-control", className)}
  placeholder={placeholder}
  options={options}
  onChange={onChange}
/>
...

I've also tried requiring it, but no matter what I do the error persists.

I am using react-react-app library. How to solve this?

  • 1
    Have you read the [documentation](https://github.com/nosir/cleave.js/blob/master/doc/reactjs-component-usage.md)? And instead of merely saying "I've tried requiring it" please show how you tried to require it, otherwise it is impossible to know what in said requiring is going wrong. – Roope Aug 22 '18 at 11:13

1 Answers1

3

Just a quick look in their github:

import "cleave.js/dist/addons/cleave-phone.your-country-here";
import Cleave from 'cleave.js/react';

...
<Cleave
  name={name}
  value={value}
  className={cx("form-control", className)}
  placeholder={placeholder}
  options={options}
  onChange={onChange}
/>
...
João Cunha
  • 9,929
  • 4
  • 40
  • 61