kaliberjs / forms

Forms for React
MIT License
4 stars 0 forks source link

Added render prop component suggestions #4

Closed peeke closed 4 years ago

peeke commented 4 years ago

Added suggestions for the render prop components, along with some (naive) implementations. This can serve as a starting point for discussion.

EECOLOR commented 4 years ago

@peeke I have filled in the implementation and slightly changed the name from useFieldValues to useFieldsValues (not sure if you agree)

I also removed FormObjectField and FormArrayField as I realized that these will always be domain specific.

Before we can release we need to add the new fields to the documentation.

peeke commented 4 years ago

@EECOLOR Agreed, we're accessing multiple values from multiple forms so useFieldsValues makes sense.

I'll see if I have some time to update the docs this week.

peeke commented 4 years ago

@EECOLOR Is see I missed a rename earlier: useFieldState should be useFormFieldState to be consistent with the naming of other hooks. Since they are undocumented, can we rename them? Maybe as a separate PR.

peeke commented 4 years ago

@EECOLOR What happens if you want to render 0 as a value? Right now it would return null. Should we change the check here?

export function FormFieldValue({ field, render }) {
  const value = useFormFieldValue(field)
  return render(value) || null
}
EECOLOR commented 4 years ago

Since they are undocumented, can we rename them? Maybe as a separate PR.

Yes, separate pull request and major version change.

What happens if you want to render 0 as a value? Right now it would return null. Should we change the check here?

Yes, we should