Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hooks-composer

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hooks-composer

yet another way to create your react hooks

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

React Hooks Composer

Tiny Javascript composition over React Hooks ( React > 16.7.0 ). Yet another way to create your hooks :)

Before

import React from 'react'

export default function Test(props) {
  const [name, setName] = React.useState('Mary')
  const [surname, setSurname] = React.useState('Poppins')
  const [language, setLanguage] = React.useState('🇬🇧')
}

After

import React from 'react'
import useHooksComposer from 'hooks-composer'

export default function Test(props) {
  const { name, surname, language, setName, setSurname, setLanguage } = useHooksComposer({
    name: 'Mary',
    surname: 'Poppins',
    language: '🇬🇧'
  })
}

How it works

Instead of creating your hooks line by line and defining the pairs for value and its setter, you can pass a static object, where each key is the name of your hook variable and the value is the initial value of the hook. The composer will create an independent hook for each key and will return an object with all values and setters named according to the convention.

Example:

import React from 'react'
import useHooksComposer from 'hooks-composer'

export function Test(props) {
  const { count, setCount } = useHooksComposer({ count: 0 })
}

Installation

 npm i hooks-composer or yarn add hooks-composer

Made with ♥ by nudelx

Keywords

FAQs

Package last updated on 12 Nov 2018

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc