Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/roydukkey/jsx-destruct

This tiny package allows you to unpack values directly in JSX statements
https://github.com/roydukkey/jsx-destruct

destructuring jsx

Last synced: about 1 month ago
JSON representation

This tiny package allows you to unpack values directly in JSX statements

Awesome Lists containing this project

README

        

# jsx-destruct

[![Release Version](https://img.shields.io/npm/v/jsx-destruct.svg)](https://www.npmjs.com/package/jsx-destruct)
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)

This tiny package allows you to unpack values directly in JSX statements. This helps avoid long object references and keeps declarations joined within your components.

## Install

Install the package:

```bash
npm install jsx-destruct
```

## Usage

```js
import { Fragment } from 'react';
import { useQuery } from 'react-query';
import destruct from 'jsx-destruct';

export function SampleComponent () {

const { isLoading, data } = useQuery('repoData', async () =>
fetch('https://api.github.com/repos/roydukkey/clean-package')
.then(async (res) => res.json())
);

return (

{isLoading &&

Loading...

}

{destruct(data, ({ name, description, owner: { login } }) => (

{name}


by {login}


{description}



))}

);

}
```

## Inspiration

1. jsx-control-statements' [`` component](https://github.com/AlexGilleran/jsx-control-statements#with-tag)
1. Handlebars' builtin [`#with` helper](https://handlebarsjs.com/guide/builtin-helpers.html#with)