@24hr/react-hooks 中文文档教程

发布于 3年前 浏览 32 项目主页 更新于 3年前

@24hr/react-hooks

所有贡献者

Build

React hooks library

Documentation

useBeforeMount

挂载前运行的钩子,适用于SSR。

useBeforeMount(() =>
    console.log('Runs only once before component mounts. Works on the server!')
)

useLocalStorage

一个与 localstorage 同步状态的钩子

/**
 * @typedef Options
 * @property {boolean} [clearOnUnmount] - Whether or not to clear the localstorage value on unmount.
 */

/**
 * A hook that syncs the state with a property in the localstorage.
 * @param {string} defaultVal - The initial value
 * @param {string} key - Mandatory key to use to store the data in localstorage.
 * @param {Options} options - Options object
 * @return {[any, function, function]} - Return the current state, a set state function and a function to clear the storage.
 */
const [state, setState, clear] = useLocalStorage('default value', 'key', { clearOnUnmount: false });

Want to contribute?

贡献很容易!

  1. 克隆 repo 并从 master 创建一个新分支。

  2. 进行更改。

  3. 运行 ./bump.sh 并选择您的更改是主要补丁还是次要补丁。

  4. 承诺并推动。

  5. 向 master 发出合并请求。 CI 管道会将您的新版本发布到 NPM!

Contributors ✨

感谢这些优秀的人 (emoji key):


Marcus Thelin

????

schmolie

????

这个项目遵循 all-contributors 规范。 欢迎任何形式的贡献!

@24hr/react-hooks

All Contributors

Build

React hooks library

Documentation

useBeforeMount

A hook that runs before mount and is suitable for SSR.

useBeforeMount(() =>
    console.log('Runs only once before component mounts. Works on the server!')
)

useLocalStorage

A hook that syncs state with localstorage

/**
 * @typedef Options
 * @property {boolean} [clearOnUnmount] - Whether or not to clear the localstorage value on unmount.
 */

/**
 * A hook that syncs the state with a property in the localstorage.
 * @param {string} defaultVal - The initial value
 * @param {string} key - Mandatory key to use to store the data in localstorage.
 * @param {Options} options - Options object
 * @return {[any, function, function]} - Return the current state, a set state function and a function to clear the storage.
 */
const [state, setState, clear] = useLocalStorage('default value', 'key', { clearOnUnmount: false });

Want to contribute?

It's easy to contribute!

  1. Clone the repo and create a new branch from master.

  2. Make your changes.

  3. Run ./bump.sh and choose if your changes are major, minor och patch.

  4. Commit and push.

  5. Make a merge request to master. The CI pipeline will publish your new version to NPM!

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Marcus Thelin

????

schmolie

????

This project follows the all-contributors specification. Contributions of any kind welcome!

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文