Socket
Book a DemoInstallSign in
Socket

klaso

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

klaso

A functional alternative to creating stateful components in React

latest
npmnpm
Version
1.2.1
Version published
Weekly downloads
6
Maintainers
1
Weekly downloads
 
Created
Source

npm PRs Welcome Open Source Love License

🍷 Klaso

A functional alternative to stateful components in React.

Install

yarn add klaso

Examples

Basic

import klaso from 'klaso'

const MyButton = ({ count, inc }) => <button onClick={inc}>{count}</button>

const MyButtonEnhanced = klaso ({
  state: { count: 5 },
  methods: ctx => ({
    inc: () => ctx.setState({ count: ctx.state.count + 1 })
  })
}) (MyButton)

Using Lifecycles

import klaso from 'klaso'

const MyButton = () => <button>Click me</button>

const MyButtonEnhanced = klaso({
  methods: ctx => ({
    componentDidMount: () => console.log('mounted'),
    componentDidUpdate: (prevProps, prevState, snapshot) => console.log(snapshot),
    getSnapshotBeforeUpdate: (prevProps, prevState) => console.log(prevProps, prevState),
  }),
  staticMethods: {
    getDerivedStateFromProps: (props, state) => console.log(props) || null,
  },
})(MyButton)

Changelog

  • v.1.2.1 -- Dec 5, 2018
    • Added init function that runs in the constructor
  • v.1.2.0 -- Sept 16, 2018
    • Fixed error "Cannot call class as a function" error when composing multiple HOC's
    • Fix display names for stack traces and react dev tools
    • New feature to override display names by passing it through the config as displayName

FAQs

Package last updated on 05 Dec 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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.