Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sanfilippopablo/babel-plugin-optimize-hook-destructuring
Babel plugin for transforming this const [value, setValue] = useState(null) to this const {0: value, 1: setValue} = useState(null);.
https://github.com/sanfilippopablo/babel-plugin-optimize-hook-destructuring
Last synced: about 2 months ago
JSON representation
Babel plugin for transforming this const [value, setValue] = useState(null) to this const {0: value, 1: setValue} = useState(null);.
- Host: GitHub
- URL: https://github.com/sanfilippopablo/babel-plugin-optimize-hook-destructuring
- Owner: sanfilippopablo
- License: gpl-3.0
- Created: 2018-10-31T16:33:34.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-08T18:58:09.000Z (about 2 years ago)
- Last Synced: 2024-09-18T10:44:49.557Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 177 KB
- Stars: 44
- Watchers: 2
- Forks: 2
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome - babel-plugin-optimize-hook-destructuring - Babel plugin for transforming this const [value, setValue] = useState(null) to this const {0: value, 1: setValue} = useState(null);. (JavaScript)
- awesome-list - babel-plugin-optimize-hook-destructuring
README
# babel-plugin-optimize-hook-destructuring
Babel plugin for transforming this `const [value, setValue] = useState(null)` to this `const {0: value, 1: setValue} = useState(null);`.
Note that this plugin only convert hooks (function name starting with `use`).
**input:**
```js
function Foo() {
// this gets converted to object destructuring:
const [count, setCount] = useState(0);// but non-hook calls are not modified:
const [a, b] = [0, 1];
const [c, d] = otherThings();
const f = 0;
}
```**output:**
```js
function Foo() {
// this gets converted to object destructuring:
const { 0: count, 1: setCount } = useState(0);// but non-hook calls are not modified:
const [a, b] = [0, 1];
const [c, d] = otherThings();
const f = 0;
}
```