1.1.1 • Published 7 months ago

damned-hook v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

damned-hook

easy to use react hook

NPM JavaScript Style Guide

Install

npm install --save damned-hook

Usage

useStateRef

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

withComposition

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>
  );
};

License

MIT ©

1.1.1

7 months ago

1.0.3

10 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago