Code Monkey home page Code Monkey logo

enform's Introduction

Hello

I develop UIs and app architectures for projects with fluid requirements.

:atom:

enform's People

Contributors

dependabot[bot] avatar moubi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

dreamdev21

enform's Issues

Export custom hook

It should expose the same api as the component with render prop.

No change there, but a more convenient way of using the library.

import { Enform } from "enform"
or
import { useForm } from "enform"
you decide...

Both render props and hooks have their use cases.

About the problems they solve (or create) read "Render props vs hooks".

Investigate fixing re-rendering challenge

Enform doesn't update its internal state when new initial prop value is passed. Is that desired?

It means, consumer components should tell it explicitly when to re-render. That is usually done via key prop. More on that matter could be found in the docs โš ๏ธ

Other libraries like Formik fx. provide additional prop to manage that behaviour.

This is normal, but the question is does it make sense? Shouldn't Enform handle re-rendering by default? If YES, it could be done with something like:

const [initial, setInitial] = useState({ ...props.initial });

...

if (props.initial !== initial) {
  seInitial({ ...initial })
}

The outcome of this issue should be a test case (preferable in codesandbox forking on of the examples) and an answer YES/NO.

Update state when initial prop changes

Whenever initial prop changes (getting new values as a result of an API call) Enform should update its internal state and display the new defaults.

The solution should use ref comparison.

Make clearFields work as reset

Currently clearFields tries to empty the form. This is not very useful since the common case would be to reset the form.

clearFields should be renamed to resetFields and as a result it will revert the values to initial values.

Allow for setting errors from outside

Sometimes forms need to react on payload as a result of an API call. In such cases API response may contain specific errors per field, which we are interested on display in the form.

In order that to work Enform needs to be told somehow about these errors. In Formik this is done via setErrors() method (jaredpalmer/formik#33).

That opens door for more use cases where one may need to manipulate Enform's internal state from outside. Let's say updating the values programmatically.

The solution to all these could be a general setState() method fx.

setState({
  values: {
    [fieldName]: value,
    ...
  },
  errors: {
    [fieldName]: errorMessage,
    ...
  },
  ...
})

Align initial error values with validation prop

Currently the initial error state is built based on initial prop values (default field values) and defaults to false for all fields. That might be problematic in some cases, fx. passing the error to a child component on render that expects value which is non boolean.

In order to cover the case our initial errors state value should be based on the validation prop if present.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.