
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
@de-formed/react-validations
Advanced tools
De-Formed is a library for designing modular, event-driven form and data validations. Bind the things you need; ignore the things you don't. De-Formed will take care of the rest so that you can design your architecture the way you want to.
yarn add @de-formed/react-validations
npm i @de-formed/react-validations
// usePersonValidation.ts
import { useValidation } from '@de-formed/react-validations';
export const usePersonValidation = () => {
return useValidation<Person>({
firstName: [
{
error: 'First Name is required.',
validation: ({ firstName }) => firstName.length > 0,
},
{
error: 'First Name cannot be longer than 20 characters.',
validation: ({ firstName }) => firstName.length <= 20,
},
],
lastName: [
{
error: 'Last Name is required.',
validation: ({ lastName }) => lastName.length > 0,
},
{
error: 'Last Name cannot be longer than 20 characters.',
validation: ({ lastName }) => lastName.length <= 20,
},
{
error: ({ lastName }) =>
`${lastName} must be Ross if fist name is Bob.`,
validation: ({ firstName, lastName }) => {
return firstName === 'Bob' ? lastName === 'Ross' : true;
},
},
],
});
};
Bind the things you need; ignore the things you don't. De-Formed will take care of the rest.
// PersonForm.component.tsx
import React from 'react';
import { usePersonValidation } from './usePersonValidation';
export const PersonForm = ({ person, onChange }) => {
const {
getError,
validateAll,
validateOnChange,
validateOnBlur
} = usePersonValidation();
const handleSubmit = () => {
if (validateAll(person) {
// submit logic
}
};
return (
<>
<div>
<label>First Name</label>
<input
name="firstName"
onBlur={validateOnBlur(person)}
onChange={validateOnChange(onChange, person)}
value={person.firstName}
/>
{getError('firstName') && <p>{getError('firstName')}</p>}
</div>
<div>
<label>Last Name</label>
<input
name="lastName"
onBlur={validateOnBlur(person)}
onChange={validateOnChange(onChange, person)}
value={person.lastName}
/>
{getError('lastName') && <p>{getError('lastName')}</p>}
</div>
<button onClick={handleSubmit}>Submit</button>
</>
);
};
Guided walkthrough of how to customize De-Formed to the moon 🚀
API documentation.
More examples and CodeSandboxes.
This project is licensed under the terms of the MIT license.
FAQs
Modular, Function-driven Validations
The npm package @de-formed/react-validations receives a total of 2 weekly downloads. As such, @de-formed/react-validations popularity was classified as not popular.
We found that @de-formed/react-validations demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.