0.1.43 • Published 5 years ago

react-hooks-binding v0.1.43

Weekly downloads
42
License
MIT
Repository
github
Last release
5 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

5 years ago

0.1.42

5 years ago

0.1.41

5 years ago

0.1.40

5 years ago

0.1.37

5 years ago

0.1.39

5 years ago

0.1.32

5 years ago

0.1.33

5 years ago

0.1.34

5 years ago

0.1.35

5 years ago

0.1.36

5 years ago

0.1.30

5 years ago

0.1.31

5 years ago

0.1.29

5 years ago

0.1.27

6 years ago

0.1.28

6 years ago

0.1.24

6 years ago

0.1.25

6 years ago

0.1.26

6 years ago

0.1.23

6 years ago

0.1.22

6 years ago

0.1.20

6 years ago

0.1.18

6 years ago

0.1.19

6 years ago

0.1.17

6 years ago

0.1.16

6 years ago

0.1.12

6 years ago

0.1.13

6 years ago

0.1.15

6 years ago

0.1.11

6 years ago

0.1.10

6 years ago

0.1.9

6 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.2

6 years ago

0.1.3

6 years ago

0.1.1

6 years ago