Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-slim-use-form

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-slim-use-form

A form validation library implemented by React Hooks.

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

react-slim-use-form

A form validation library implemented by React Hooks. Easy to implement form state management, validation and data submission.

How to install

npm install react-slim-use-form or yarn add react-slim-use-form

How to use

interface FormData {
  email: string
  password: string
}

export default function validate(values: FormData) {
  const errors: Partial<FormData> = {}
  if (!values.email) {
    errors.email = 'error message'
  } else if (!EMAIL_REGEXP.test(values.email)) {
    errors.email = 'error message'
  }
  if (!values.password) {
    errors.password = 'error message'
  } else if (!PASS_REGEXP.test(values.password)) {
    errors.password =
      'error message'
  }
  return errors
}

export const LoginScreen: React.FC = () => {
  const loginReq = useCallback(() => {}, [])
  const { values, errors, handleChange, handleSubmit } = useForm(
    { email: '', password: '' },
    loginReq,
    validate
  )
  return (
    <View>
        <TextField
          value={values.email}
          error={!!errors.email}
          helperText={errors.email}
          onChangeText={useCallback(
            (text: string) => handleChange(text, 'email'),
            []
          )}
        />
        <TextField
          value={values.password}
          error={!!errors.password}
          helperText={errors.password}
          secureTextEntry
          onChangeText={useCallback(
            (text: string) => handleChange(text, 'password'),
            []
          )}
        />
        <Button title="Login"onPress={handleSubmit} />
    </View>
  )
}

Keywords

FAQs

Package last updated on 18 Jul 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc