A Component for making element's content editable with input like features (e.g. max length)
npm i @benson.liao/react-content-editable
const React = require('react');
const {useState} = require('react');
const ContentEditable = require('@benson.liao/react-content-editable').default;
const App = () => {
const [text, setText] = useState('')
const onChange = (value) => {
setText(value)
}
return (
<ContentEditable
tag='p'
maxLength='20'
onChange={onChange}
value={text}
/>
)
}
# es6
import React, { useState } from 'react'
import ContentEditable from "@benson.liao/react-content-editable";
const App = () => {
const [text, setText] = useState('')
const onChange = (value) => {
setText(value)
}
return (
<ContentEditable
tag='p'
maxLength='20'
onChange={onChange}
value={text}
/>
)
}
<Editable
tag="p"
maxLength='20'
onChange={onChange}
value={data}
/>
<Editable
readOnly
tag="h1"
maxLength='20'
onChange={onChange}
/>
We would love some contributions! Check out this document to get started.
- Improve onPaste handler