0.1.43 • Published 3 years ago

react-hooks-binding v0.1.43

Weekly downloads
42
License
MIT
Repository
github
Last release
3 years ago

react-hooks-binding

React hooks binding is manage states and context like redux just more simple.

Features:

Binding to relative DataContext. Binding to global DataContext. Binding Source - default is the relative DataContext, which can be Binding or DataContext. Binding contextKey - set the source to global DataContext by key value. Binding Mode - three modes for binding oneWay, twoWay, oneWayToSource. Binding Path - the path to the binding source property. Binding convert - way to adjust the real value. Binding convertBack - way to convert back to real value.
MultiBinding - from multiple sources to one value.

Typescript definitions

Installation

npm install react-hooks-binding --save

Basic Usage

Wrap your form with DataContext and then useBinding in every place you need to get or set value from DataContext.

Example:

import { DataContextProvider } from 'react-hooks-binding';

<DataContextProvider
  context={{
    payment: {
      cardNumber: '',
      expiry: '',
      cardCode: ''
    }
  }}
>
  <PaymentView />
</DataContextProvider>;

export default function PaymentView() {
  return (
    <>
      <CardNumber />
      <CardExpiry />
      <CardCode />
    </>
  );
}

import { useBinding, BindingMode } from 'react-hooks-binding/build';

export default function CardNumber() {
  let cardNumberBinding = useBinding({
    path: 'payment.cardNumber',
    mode: BindingMode.twoWay,
    convert: value => {
      let formated = payment.fns.formatCardNumber(value);
      return formated;
    },
    convertBack: (source, value) => {
      let cardNumber = string(value).replaceAll(' ', '').s;
      return cardNumber;
    }
  });

  return (
    <TextInput
      value={cardNumberBinding.value}
      onChangeText={rawCardNumber => {
        cardNumberBinding.setValue(rawCardNumber);
      }}
    />
  );
}
0.1.43

3 years ago

0.1.42

3 years ago

0.1.41

3 years ago

0.1.40

3 years ago

0.1.37

4 years ago

0.1.39

4 years ago

0.1.32

4 years ago

0.1.33

4 years ago

0.1.34

4 years ago

0.1.35

4 years ago

0.1.36

4 years ago

0.1.30

4 years ago

0.1.31

4 years ago

0.1.29

4 years ago

0.1.27

4 years ago

0.1.28

4 years ago

0.1.24

4 years ago

0.1.25

4 years ago

0.1.26

4 years ago

0.1.23

4 years ago

0.1.22

4 years ago

0.1.20

4 years ago

0.1.18

4 years ago

0.1.19

4 years ago

0.1.17

4 years ago

0.1.16

4 years ago

0.1.12

4 years ago

0.1.13

4 years ago

0.1.15

4 years ago

0.1.11

4 years ago

0.1.10

4 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.2

4 years ago

0.1.3

4 years ago

0.1.1

4 years ago