1.1.4 • Published 8 months ago

use-logic-block v1.1.4

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

use-logic-block

React hook for using logic-block in functional components

Installation

Just add it to project dependencies

yarn add use-logic-block
// or
npm install --save use-logic-block

Example

import React from 'react'
import Block, { value, fields } from 'logic-block'
import useLogicBlock from 'use-logic-block'

const block = Block({
  counter: value(0),
  doneEdge: value(10),
  isDone: fields((c, e) => { return c >= e }, ['counter', 'doneEdge'])
})

function Comp(props) {
  const { value, update } = useLogicBlock(block, { doneEdge: props.edge })

  return (
    <div className="root">
      <span>{`${value.counter} / ${value.doneEdge}`}</span>
      <button
        className="button"
        disabled={value.isDone}
        onClick={() => update({ counter: value.counter + 1 })}
      >
        INCREASE COUNTER
      </button>
    </div>
  )
}

API

useLogicBlock is a react hook (function).

ArgumentTypeOptional?Description
blockBlockFactoryMandatoryThe block which will use for processing value. If block will change during life time of a component, the value will be immediately re-processed with initialValue that will be setted on the time.
initialValueObjectOptionalInitial value for block instance. If it will be changed during lifetime of a component, value will be re-rendered with new initial data and instance will be processed.
onUpdate(newValue: Object) => voidOptionalCallback which will invoke on every update of the value.

Author

Ilya Melishnikov

LICENSE

MIT

1.1.1

8 months ago

1.1.0

8 months ago

1.1.4

8 months ago

1.1.3

8 months ago

1.1.2

8 months ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago