1.0.4 • Published 7 years ago
recompose-utils v1.0.4
Recompose utilities
withEvents, withValidation for react recompose
install
npm i recompose-utilsor
yarn add recompose-utilswithEvents
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-utilsyou 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"
}