1.0.4 • Published 6 years ago

recompose-utils v1.0.4

Weekly downloads
5
License
ISC
Repository
github
Last release
6 years ago

Recompose utilities

withEvents, withValidation for react recompose

install

npm i recompose-utils

or

yarn add recompose-utils

withEvents

import withEvents

import { withEvents } from "recompose-utils"

and than you have emmiters and handlers

you can pass withEvents to composed component where you want to emitt event

  withEvents({
    emitters: ['toggleAuthModal'],
  }),

now you have emitters prop to your component and you can fire event like this

  <button onClicl={() => props.emitters.toggleAuthModal('hi from here') }>
    fire event
  </button>

and you pass withEvents to composed component where you want to listen to that event

  withEvents({
    handlers: {
      toggleAuthModal: (props) => (event) => {
        console.log("event:: toggleAuthModal -fired with data::", event)
      },
    },
  }),

withValidation

import withValidation

import { withValidation } from recompose-utils

you can pass withValidation to composed component with wurles

  withValidation({
    name: {
      rules: "required",
      messages: {
        required: "This field is required"
      }
    },
    email: {
      rules: 'require|email',
      messages: {
        require: "This field is required",
        email: "Please, fill with valid email"
      }
    },
  }),

and you can validate you form like

  withHandlers({
    handleSave: (props) => () => {
      const isValid = validate(props.formData) // returnes true or false
    },
  }),

and you can access your errored filds in errors props error props would be something like this

  errors: {
    name: "",
    email: "Please, fill with valid email"
  }
1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago