use-string-diff
v1.4.6
Published
custom react hook to get the difference between two strings
Downloads
86
Maintainers
Readme
Installation
This module is distributed via NPM which is bundled with NodeJS and should be installed as one of your project's dependencies:
npm install use-string-diff --save
or yarn add use-string-diff
Usage
Single Value
import { useStringDiff } from 'use-string-diff'
const MyComponent = () => {
const [state, setState] = useState('');
const difference = useStringDiff(value);
return (
<div>
<input
onChange={(event) => {
setState(event.target.value);
}}
value={value}
/>
</div>
)
}
Two Values
import { useStringDiff } from 'use-string-diff'
const INITIAL_STRING = 'Initial String';
const MyComponent = () => {
const [state, setState] = useState(INITIAL_STRING);
const difference = useStringDiff(INITIAL_STRING, state);
return (
<div>
<input
onChange={(event) => {
setState(event.target.value);
}}
value={value}/>
</div>
)
}
🐛 Bugs
Please file an issue for bugs, missing documentation, or unexpected behavior.
LICENSE
MIT