This documentation is for the old Kea 1.0. To see the latest docs, click here!

connect(options)

Shorthand for kea({ connect: options })

It's very handy for connecting actions and values to class components.

Usage

import React, { Component } from 'react'
import { connect } from 'kea'

import menuLogic from '../menu/logic'

@connect({
  actions: [
    menuLogic, [
      'openMenu',
      'closeMenu'
    ]
  ],
  values: [
    menuLogic, [
      'isOpen as isMenuOpen'
    ]
  ]
})
export default class MyComponent extends Component {
  render () {
    const { isMenuOpen } = this.props
    const { openMenu, closeMenu } = this.actions

    return (
      <div>
        <button onClick={isMenuOpen ? closeMenu : openMenu}>Toggle menu</button>
      </div>
    )
  }
}