easy to use react hook
npm install --save damned-hook
Merge useState and useRef to solve some closure problems.
import React, { useEffect } from 'react'
import { useStateRef } from 'damned-hook'
const App = () => {
const [ref, setState] = useStateRef(0)
setInterval(() => {
console.log(ref.current) // update every seconds
setState(ref.current+1) // can trigger dom update.
console.log(ref.current) // change synchronously
}, 1000)
return <div>
current count: {ref.current}
</div>
}
export default App
It's a hoc function for create the input component which compatible with composited language, like Chinese etc.
import { withComposition } from 'damned-hook';
const ChineseInput = withComposition('input');
const ChineseInputSample = () => {
const [value, setValue] = useState('');
const [finalValue, setFinalValue] = useState(value);
return (
<div>
<label>please input chinese or other composised language </label>
<ChineseInput
value={value}
onChange={(e) => setValue(e.target.value)}
onFinalChange={(e) => setFinalValue(e.target.value)}
/>
<label> value: {value} ; </label>
<label>final value: {finalValue}</label>
</div>
);
};