New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-closure-hooks

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-closure-hooks

some hooks for resolve closure problem in react hooks

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

react-closure-hooks

reexport react hooks, and add useEvent. They are useful for solving the closure problem in react hooks.

NPM version NPM downloads

install

npm install --save react-closure-hooks

or

yarn add react-closure-hooks

usage

// Test
import React from 'react';
import { Search } from 'antd';
import { useState, useEvent } from 'react-closure-hooks';
import API from '@/request';

const Test = () => {
  const [searchKey, setSearchKey] = useState('');
  const [result, setResult] = useState('');

  const doQuery = useEvent(async () => {
    const result = await API.query({
      searchKey
    });
    setResult(result);
  });

  const doSearch = useEvent(async (e) => {
    await setSearchKey(e.target.value);
    doQuery();
  });

  return (
    <div>
      <Search 
        value={searchKey} 
        onSearch={doSearch}
      ><br />
      <div>{result}</div>
    </div>
  );
};

export default Test;

or use useStateWithPromise

// Test
import React, { useState } from 'react';
import { Search } from 'antd';
import { useStateWithPromise, useEvent } from 'react-closure-hooks';
import API from '@/request';

const Test = () => {
  const [searchKey, setSearchKey] = useStateWithPromise('');
  const [result, setResult] = useState('');

  const doQuery = useEvent(async () => {
    const result = await API.query({
      searchKey
    });
    setResult(result);
  });

  const doSearch = useEvent(async (e) => {
    await setSearchKey(e.target.value);
    doQuery();
  });

  return (
    <div>
      <Search 
        value={searchKey} 
        onSearch={doSearch}
      ><br />
      <div>{result}</div>
    </div>
  );
};

export default Test;

License

MIT

Keywords

react

FAQs

Package last updated on 20 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts