1.0.5 • Published 2 years ago

react-async-button-z v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Description
  • Simple lock button.
Usage
npm install --save react-async-button-z

Import the module in the place you want to use:

import AsyncButton from "react-async-button-z";
import "react-async-button-z/build/styles.css";

Snippet

    // handler by props
    const [isAsync, setAsync] = useState(false)

    const fetchApi() {
        setAsync(true)
        fetch('')....finally(() => setAsync(false))
    }

    <AsyncButton isAsync={isAsync} onClick={fetchApi} text="abcd" />
    // handler by async Promise
    const fetchApi = () => {
        return new Promise(resovle => {
            // do something
            setTimeout(() => {
                // make done
                resovle()
            }, 5000)
        })
    }

    <AsyncButton asyncFunc={fetchApi} text="abcd" loadingText="loading" />
Props
propstypedescription
classNameString
themeStringdefault: ring
indicatorColorStringdefault: #000000
sizeNumberdefault: 10 (indicator size)
isAsyncbooleanyour handler async by props (change true /false )
onClickfuncyour handler async by props
textanybetter if it is string label
loadingTextanywhen async
timeoutnumberif auto make icon async (default: 0 => none)
asyncFuncfuncyour handler async by a promise
Note
Example

LIVE EXAMPLE

A working example can be found in the example directory.

npm install
npm run dev
npm run start

License

MIT