Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: createFormControl and subscribe function #11522

Draft
wants to merge 41 commits into
base: master
Choose a base branch
from

Conversation

bluebill1049
Copy link
Member

@bluebill1049 bluebill1049 commented Feb 17, 2024

Proposal

Expose createFormControl method and enable subscribe outside of the react component. This would solve a lot of subscriptions within child component issues.

⚡️ createFormControl

  • Allow us to start subscribing before the react life cycle
  • This is completely optional and once everything is working, we can switch to using the core library
const formControl = createFormControl(props)

function App() {
  const { register } = useForm({
    formControl,
  })

  return <form />
}

function Test() {
  useFormState({
    control: formControl.control // no longer need context api
  })
}

⚡️ subscribe

  • subscribe form state update without re-render
  • subscribe outside of the react component
const formControl = createFormControl(props)

control.subscribe({
  formState: { isDirty: true },
  callback: (formState) => {
    if (formState.isDirty) {
      // do something here
    }
  }
})

function App() {
  const { register } = useForm({
    formControl,
  })

  return <form />
}

Copy link

codesandbox bot commented Feb 17, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link
Contributor

github-actions bot commented Feb 17, 2024

Size Change: +80 B (0%)

Total Size: 20.8 kB

Filename Size Change
dist/index.cjs.js 10.4 kB +37 B (0%)
dist/index.umd.js 10.5 kB +43 B (0%)

compressed-size-action

@bluebill1049 bluebill1049 changed the title feat: createFormControl outside of component feat: createFormControl and subscribe function Feb 17, 2024
@bluebill1049 bluebill1049 marked this pull request as draft February 18, 2024 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant