Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/MarvelSQ/use-properties-hook

A React hook - instance variables with useRef
https://github.com/MarvelSQ/use-properties-hook

hook react

Last synced: 2 months ago
JSON representation

A React hook - instance variables with useRef

Lists

README

        

# use-properties-hook

bind variables to current Component, like **_class-properties_**

## install

```
npm install @marvelsq/use-properties-hook
```

## use
- **useProperty(any):any** bind single variable
- **useProperties(...any):[...any]** bind multiple variable
```js
import React, { useState } from 'react';
import { useProperties } from '@marvelsq/use-properties-hook';

export default function App({ data, updateData }) {
// state
const [active, setActive] = useState(null);
// functions always same
const [handleClick, handleRemove] = useProperties(
index => setActive(index),
targetIndex => {
updateData(data.filter((data, index) => targetIndex !== index));
setActive(data[index - 1] ? index - 1 : null);
}
);

return ;
}
```

**inspired by [Making setInterval Declarative with React Hooks](https://overreacted.io/making-setinterval-declarative-with-react-hooks/)**