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

iota-hook

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

iota-hook

Manage your components effects and state with methods.

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

💫 Iota

Manage stateful logic with class methods like the good ol' times, but with reuable hooks.

Install

npm install iota-hook

Quickstart

Create a ususable instance of iota to grab a remote api data via debounce from incoming props

import createIota from 'iota-hook'
import debounce from 'lodash.debounce'
import searchQuery from './searchQuery'

const useLocationHook = createIota({
  init: (self) => {
    self.state = { searchResults: [] }
  },
  didUpdate: (self) => {
    const { props, prevProps } = self
    if (props.query !== prevProps.query) {
      self.search(props.query)
    }
  },
  didMount: (self) => {
    self.search = debounce(self.search, 1000)
  },
  search: async (self, arg) => {
    const results = await searchQuery(arg)
    self.setState({ searchResults: results })
  },
  render: (self) => {
    const { state } = self

    return {
      results: state.searchResults.map((location) => {
        const [city, country] = location.split(', ')
        return { city, country }
      }),
      amount: state.searchResults.length
    }
  }
})

Then you can reuse this in any component

import useLocationHook from './useLocationHook'

function App() {
  const [searchText, setSearchText] = React.useState('')

  const data = useLocationHook({ query: searchText })

  console.log({ data }) // data is data created from render method in iota hook

  return (
    <div>
      <input type="text" onChange={(e) => setSearchText(e.target.value)} />
    </div>
  );
}


Create

FAQs

Package last updated on 07 Oct 2022

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