kaliberjs / forms

Forms for React
MIT License
4 stars 0 forks source link

Add subscribeToFieldState method #15

Closed EECOLOR closed 4 years ago

EECOLOR commented 4 years ago

The snapshot functions originally gave only access to specific values. This pull request exposes a new function which exposes the field as argument, allowing for more options.

This pull request should be an answer to the question "Can we detect when isVisited changes on any form field?"

peeke commented 4 years ago

Right, this explains why a custom hook I wrote wasn't working as expected. An easy fix with this new export :)

Op do 1 okt. 2020 om 15:43 schreef EECOLOR notifications@github.com:

@EECOLOR commented on this pull request.

In example/src/domain/Full.js https://github.com/kaliberjs/forms/pull/15#discussion_r498253988:

@@ -128,3 +131,54 @@ function Conditional({ field, children, reverse = false }) { const value = useFormFieldValue(field) return (reverse ? !value : value) && children } + +function useSendSignalWhenIsVisited(form, f) {

  • const callbackRef = React.useRef(f)
  • React.useEffect(
  • () => {
  • const unsubscribe = snapshot.subscribeToFieldState(

Great question. field.state gives you the state of the field itself. So the subscription is only to changes of that particular field.

snapshot subscribes to changes in the field state and (if applicable) changes in it's children (recursively).

Your questions lead to me believe the new name is poorly choosen. I think we should rename it to subscribeToField.

— You are receiving this because your review was requested. Reply to this email directly, view it on GitHub https://github.com/kaliberjs/forms/pull/15#discussion_r498253988, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABD6O6SXGKX7PAVFPKF23MTSISBOZANCNFSM4R7HL5SQ .

--

Peeke Kuepers Lead UI/UX developer www.kaliber.net Kaliber Interactive Zeedijk 19 3513 DA Utrecht 030 287 64 00