Skip to content

Conversation

@bluebill1049
Copy link
Member

@bluebill1049 bluebill1049 commented Dec 28, 2024

close #12501

  • subscribe to the entire form but only return updated value with certain condition
type FormValue = {
  test: string;
}

const watchedValue = useWatch({
  control: methods.control,
  compute: (data: FormValue) => {
    if (data.test?.length) {
      return data.test;
    }

    return '';
  },
});
  • subscribe to a specific form value state
type FormValue = {
  test: string;
}

const watchedValue = useWatch({
  control: methods.control,
  name: 'test',
  compute: (data: string) => {
      return data.length ? data : '';
  },
});

@bluebill1049 bluebill1049 marked this pull request as draft December 28, 2024 00:08
@github-actions
Copy link
Contributor

github-actions bot commented Dec 28, 2024

Size Change: +288 B (+0.52%)

Total Size: 55.2 kB

Filename Size Change
dist/index.cjs.js 11 kB +76 B (+0.7%)
dist/index.esm.mjs 20.3 kB +139 B (+0.69%)
dist/index.umd.js 11.1 kB +73 B (+0.66%)
ℹ️ View Unchanged
Filename Size
dist/react-server.esm.mjs 12.8 kB

compressed-size-action

@bluebill1049 bluebill1049 marked this pull request as ready for review January 18, 2025 09:46
@BrendanC23
Copy link

Do you think there's value in including a name prop? This would ensure that the compute() function isn't running on every change to the form value. For example, from #12501

const displayNicknameField = useWatch({ name: 'userName', compute: currentValue => currentValue.length > 10 });

The compute function only needs to run if userName changes. It's not a big deal here because it's only doing a simple comparison, but if compute slow, it would help to run it only when necessary.

Another option would be some kind of computeDeps, which would work like useMemo/useCallback. This would be useful if there are multiple name values that should trigger the re-computation.

@BrendanC23

This comment was marked as duplicate.

@bluebill1049
Copy link
Member Author

Do you think there's value in including a name prop? This would ensure that the compute() function isn't running on every change to the form value. For example, from #12501

yea, can looking into that.

bluebill1049 and others added 18 commits April 21, 2025 11:45
* feat: improve reference update with useWatch

* update pai extrator

* Revert "update pai extrator"

This reverts commit 0b3bbd3.

* Revert "feat: improve reference update with useWatch"

This reverts commit a664a68.

* update form value reference at consumer isntead usewatch

* update api extrator
* 🐞 fix useController should unregister issue with strict mode

* chore: remove __typetest__ folder from build
* chore: upgrade app and automation deps

* update app lock

* revert app package
* feat: reference stable for useWatch defaultValue

* remove as
* 🐞 fix #12572 disabled field value not get undefined in resolver

* fix resolver data issue
* 🐞 fix #12580 valid state update with onBlur mode

* update e2e
* fix: add condition to prevent infinite render

* fix: revert pnpm-lock.yaml changes, and use a utility function instead of typing code manually

* Revert "fix: revert pnpm-lock.yaml changes, and use a utility function instead of typing code manually"

This reverts commit b86e660.

* Revert "fix: add condition to prevent infinite render."

This reverts commit 51105a6.

* fix: use a utility function instead of typing code manually
… the `FormProvider` context (#12642)

* 🐞 fix #12632 use useLayoutEffect instead of useEffect to subscribe components earlier than before

* 🧪 test(useFieldArray): Update the result array to reflect the outcomes of the modified logic

* 🧪 test(setError): “Add a test case for using setError within the useEffect callback in FormProvider as mentioned in the issue
…#12635)

* add test scenario for #12634

* fix(useForm): set `values` immediately on first render
* upgrade deps and ts to 5.8.0

* app deps upgrade

* update prettier

* Revert "app deps upgrade"

This reverts commit aaabc46.

* update pnpm lock
curly: 'error',
'no-extra-boolean-cast': 'error',
'cypress/unsafe-to-chain-command': 'off',
'@typescript-eslint/no-unnecessary-type-constraint': 'warn',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is no longer necessary since #12771 has been merged!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh nice, i will remove it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to get an rc version out this weekend. It should be a good feature for all.

@bluebill1049 bluebill1049 changed the title feat: compute prop for useWatch subscription 🧮 feat: compute prop for useWatch subscription May 17, 2025
@bluebill1049 bluebill1049 merged commit 234396c into master Jul 5, 2025
6 checks passed
@bluebill1049 bluebill1049 deleted the close-feature-request-12501 branch July 5, 2025 23:30
EItanya pushed a commit to kagent-dev/kagent that referenced this pull request Aug 15, 2025
![snyk-top-banner](https://res.cloudinary.com/snyk/image/upload/r-d/scm-platform/snyk-pull-requests/pr-banner-default.svg)


<h3>Snyk has created this PR to upgrade react-hook-form from 7.58.1 to
7.61.0.</h3>

:information_source: Keep your dependencies up-to-date. This makes it
easier to fix existing vulnerabilities and to more quickly identify and
fix newly disclosed vulnerabilities when they affect your project.

<hr/>


- The recommended version is **4 versions** ahead of your current
version.

- The recommended version was released **21 days ago**.



<details>
<summary><b>Release notes</b></summary>
<br/>
  <details>
    <summary>Package name: <b>react-hook-form</b></summary>
    <ul>
      <li>
<b>7.61.0</b> - <a
href="https://redirect.github.com/react-hook-form/react-hook-form/releases/tag/v7.61.0">2025-07-23</a></br><p>🧮
feat: compute prop for useWatch subscription (<a class="issue-link
js-issue-link" data-error-text="Failed to load title"
data-id="2761362352" data-permission-text="Title is private"
data-url="react-hook-form/react-hook-form#12503"
data-hovercard-type="pull_request"
data-hovercard-url="/react-hook-form/react-hook-form/pull/12503/hovercard"
href="https://redirect.github.com/react-hook-form/react-hook-form/pull/12503">#12503</a>)</p>
<ul>
<li>subscribe to the entire form but only return updated value with
certain condition</li>
</ul>
<div class="highlight highlight-source-tsx notranslate position-relative
overflow-auto" data-snippet-clipboard-copy-content="type FormValue = {
  test: string;
}

const watchedValue = useWatch({
  control: methods.control,
  compute: (data: FormValue) =&gt; {
    if (data.test?.length) {
      return data.test;
    }

    return '';
  },
});"><pre><span class="pl-k">type</span> <span
class="pl-smi">FormValue</span> <span class="pl-c1">=</span> <span
class="pl-kos">{</span>
<span class="pl-c1">test</span>: <span class="pl-smi">string</span><span
class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">const</span> <span class="pl-s1">watchedValue</span>
<span class="pl-c1">=</span> <span class="pl-en">useWatch</span><span
class="pl-kos">(</span><span class="pl-kos">{</span>
<span class="pl-c1">control</span>: <span
class="pl-s1">methods</span><span class="pl-kos">.</span><span
class="pl-c1">control</span><span class="pl-kos">,</span>
<span class="pl-en">compute</span>: <span class="pl-kos">(</span><span
class="pl-s1">data</span>: <span class="pl-smi">FormValue</span><span
class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span
class="pl-kos">{</span>
<span class="pl-k">if</span> <span class="pl-kos">(</span><span
class="pl-s1">data</span><span class="pl-kos">.</span><span
class="pl-c1">test</span><span class="pl-kos">?.</span><span
class="pl-c1">length</span><span class="pl-kos">)</span> <span
class="pl-kos">{</span>
<span class="pl-k">return</span> <span class="pl-s1">data</span><span
class="pl-kos">.</span><span class="pl-c1">test</span><span
class="pl-kos">;</span>
    <span class="pl-kos">}</span>

<span class="pl-k">return</span> <span class="pl-s">''</span><span
class="pl-kos">;</span>
  <span class="pl-kos">}</span><span class="pl-kos">,</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span
class="pl-kos">;</span></pre></div>
<ul>
<li>subscribe to a specific form value state</li>
</ul>
<div class="highlight highlight-source-tsx notranslate position-relative
overflow-auto" data-snippet-clipboard-copy-content="type FormValue = {
  test: string;
}

const watchedValue = useWatch({
  control: methods.control,
  name: 'test',
  compute: (data: string) =&gt; {
      return data.length &gt; 3 ? data : '';
  },
});"><pre><span class="pl-k">type</span> <span
class="pl-smi">FormValue</span> <span class="pl-c1">=</span> <span
class="pl-kos">{</span>
<span class="pl-c1">test</span>: <span class="pl-smi">string</span><span
class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">const</span> <span class="pl-s1">watchedValue</span>
<span class="pl-c1">=</span> <span class="pl-en">useWatch</span><span
class="pl-kos">(</span><span class="pl-kos">{</span>
<span class="pl-c1">control</span>: <span
class="pl-s1">methods</span><span class="pl-kos">.</span><span
class="pl-c1">control</span><span class="pl-kos">,</span>
<span class="pl-c1">name</span>: <span class="pl-s">'test'</span><span
class="pl-kos">,</span>
<span class="pl-en">compute</span>: <span class="pl-kos">(</span><span
class="pl-s1">data</span>: <span class="pl-smi">string</span><span
class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span
class="pl-kos">{</span>
<span class="pl-k">return</span> <span class="pl-s1">data</span><span
class="pl-kos">.</span><span class="pl-c1">length</span> <span
class="pl-c1">&gt;</span> <span class="pl-c1">3</span> ? <span
class="pl-s1">data</span> : <span class="pl-s">''</span><span
class="pl-kos">;</span>
  <span class="pl-kos">}</span><span class="pl-kos">,</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span
class="pl-kos">;</span></pre></div>
<p>👨‍🔧 trigger watch callbacks in response to value changes only (<a
class="issue-link js-issue-link" data-error-text="Failed to load title"
data-id="3210030061" data-permission-text="Title is private"
data-url="react-hook-form/react-hook-form#12945"
data-hovercard-type="pull_request"
data-hovercard-url="/react-hook-form/react-hook-form/pull/12945/hovercard"
href="https://redirect.github.com/react-hook-form/react-hook-form/pull/12945">#12945</a>)<br>
🙏 track name with setValue subscription callbacks (<a class="issue-link
js-issue-link" data-error-text="Failed to load title"
data-id="3210194804" data-permission-text="Title is private"
data-url="react-hook-form/react-hook-form#12946"
data-hovercard-type="pull_request"
data-hovercard-url="/react-hook-form/react-hook-form/pull/12946/hovercard"
href="https://redirect.github.com/react-hook-form/react-hook-form/pull/12946">#12946</a>)<br>
⌨️ fix: watch return type based on defaultValue (<a class="issue-link
js-issue-link" data-error-text="Failed to load title"
data-id="3156326445" data-permission-text="Title is private"
data-url="react-hook-form/react-hook-form#12896"
data-hovercard-type="pull_request"
data-hovercard-url="/react-hook-form/react-hook-form/pull/12896/hovercard"
href="https://redirect.github.com/react-hook-form/react-hook-form/pull/12896">#12896</a>)<br>
🐞 fix <a class="issue-link js-issue-link" data-error-text="Failed to
load title" data-id="3226443079" data-permission-text="Title is private"
data-url="react-hook-form/react-hook-form#12959"
data-hovercard-type="issue"
data-hovercard-url="/react-hook-form/react-hook-form/issues/12959/hovercard"
href="https://redirect.github.com/react-hook-form/react-hook-form/issues/12959">#12959</a>
subscribe with latest defaultValues <a class="issue-link js-issue-link"
data-error-text="Failed to load title" data-id="3226946310"
data-permission-text="Title is private"
data-url="react-hook-form/react-hook-form#12961"
data-hovercard-type="pull_request"
data-hovercard-url="/react-hook-form/react-hook-form/pull/12961/hovercard"
href="https://redirect.github.com/react-hook-form/react-hook-form/pull/12961">#12961</a><br>
🐞 fix: handle explicit "multipart/form-data" encType in Form Component
(<a class="issue-link js-issue-link" data-error-text="Failed to load
title" data-id="3212769870" data-permission-text="Title is private"
data-url="react-hook-form/react-hook-form#12948"
data-hovercard-type="pull_request"
data-hovercard-url="/react-hook-form/react-hook-form/pull/12948/hovercard"
href="https://redirect.github.com/react-hook-form/react-hook-form/pull/12948">#12948</a>)<br>
🐞 fix(build): Remove React wildcard import to resolve ESM build issues
(<a class="issue-link js-issue-link" data-error-text="Failed to load
title" data-id="3206776702" data-permission-text="Title is private"
data-url="react-hook-form/react-hook-form#12942"
data-hovercard-type="pull_request"
data-hovercard-url="/react-hook-form/react-hook-form/pull/12942/hovercard"
href="https://redirect.github.com/react-hook-form/react-hook-form/pull/12942">#12942</a>)<br>
🦭 chore: improve exclude patterns (<a class="issue-link js-issue-link"
data-error-text="Failed to load title" data-id="3202497669"
data-permission-text="Title is private"
data-url="react-hook-form/react-hook-form#12935"
data-hovercard-type="pull_request"
data-hovercard-url="/react-hook-form/react-hook-form/pull/12935/hovercard"
href="https://redirect.github.com/react-hook-form/react-hook-form/pull/12935">#12935</a>)<br>
🐿️ chore: remove unused omit function (<a class="issue-link
js-issue-link" data-error-text="Failed to load title"
data-id="3225961191" data-permission-text="Title is private"
data-url="react-hook-form/react-hook-form#12958"
data-hovercard-type="pull_request"
data-hovercard-url="/react-hook-form/react-hook-form/pull/12958/hovercard"
href="https://redirect.github.com/react-hook-form/react-hook-form/pull/12958">#12958</a>)</p>
<p>Big thanks to <a class="user-mention notranslate"
data-hovercard-type="user" data-hovercard-url="/users/joshkel/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://redirect.github.com/joshkel">@ joshkel</a> for helping
with some of the subscription bugs! and also <a class="user-mention
notranslate" data-hovercard-type="user"
data-hovercard-url="/users/kamja44/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://redirect.github.com/kamja44">@ kamja44</a>, <a
class="user-mention notranslate" data-hovercard-type="user"
data-hovercard-url="/users/mrazauskas/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://redirect.github.com/mrazauskas">@ mrazauskas</a>, <a
class="user-mention notranslate" data-hovercard-type="user"
data-hovercard-url="/users/codepunkt/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://redirect.github.com/codepunkt">@ codepunkt</a>, <a
class="user-mention notranslate" data-hovercard-type="user"
data-hovercard-url="/users/afontcu/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://redirect.github.com/afontcu">@ afontcu</a> and <a
class="user-mention notranslate" data-hovercard-type="user"
data-hovercard-url="/users/rururux/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://redirect.github.com/rururux">@ rururux</a></p>
      </li>
      <li>
<b>7.60.0</b> - <a
href="https://redirect.github.com/react-hook-form/react-hook-form/releases/tag/v7.60.0">2025-07-04</a></br><p>🦘
feat: <code>reset</code> new <code>keepFieldsRef</code> options keep
fields reference (<a class="issue-link js-issue-link"
data-error-text="Failed to load title" data-id="3191330156"
data-permission-text="Title is private"
data-url="react-hook-form/react-hook-form#12923"
data-hovercard-type="pull_request"
data-hovercard-url="/react-hook-form/react-hook-form/pull/12923/hovercard"
href="https://redirect.github.com/react-hook-form/react-hook-form/pull/12923">#12923</a>)</p>
<div class="highlight highlight-source-tsx notranslate position-relative
overflow-auto" data-snippet-clipboard-copy-content="// This option will
skip input reference gets reset and avoid re-register input reference
after reset
reset(data, { keepFieldsRef: true })"><pre><span class="pl-c">// This
option will skip input reference gets reset and avoid re-register input
reference after reset</span>
<span class="pl-en">reset</span><span class="pl-kos">(</span><span
class="pl-s1">data</span><span class="pl-kos">,</span> <span
class="pl-kos">{</span> <span class="pl-c1">keepFieldsRef</span>: <span
class="pl-c1">true</span> <span class="pl-kos">}</span><span
class="pl-kos">)</span></pre></div>
      </li>
      <li>
<b>7.60.0-next.0</b> - <a
href="https://redirect.github.com/react-hook-form/react-hook-form/releases/tag/v7.60.0-next.0">2025-07-01</a></br><p>🦘
feat: <code>reset</code> new <code>keepFieldsRef</code> options keep
fields reference (<a class="issue-link js-issue-link"
data-error-text="Failed to load title" data-id="3191330156"
data-permission-text="Title is private"
data-url="react-hook-form/react-hook-form#12923"
data-hovercard-type="pull_request"
data-hovercard-url="/react-hook-form/react-hook-form/pull/12923/hovercard"
href="https://redirect.github.com/react-hook-form/react-hook-form/pull/12923">#12923</a>)</p>
<div class="highlight highlight-source-tsx notranslate position-relative
overflow-auto" data-snippet-clipboard-copy-content="// This option will
skip input reference gets reset and avoid re-register input reference
after reset
reset(data, { keepFieldsRef: true })"><pre><span class="pl-c">// This
option will skip input reference gets reset and avoid re-register input
reference after reset</span>
<span class="pl-en">reset</span><span class="pl-kos">(</span><span
class="pl-s1">data</span><span class="pl-kos">,</span> <span
class="pl-kos">{</span> <span class="pl-c1">keepFieldsRef</span>: <span
class="pl-c1">true</span> <span class="pl-kos">}</span><span
class="pl-kos">)</span></pre></div>
      </li>
      <li>
<b>7.59.0</b> - <a
href="https://redirect.github.com/react-hook-form/react-hook-form/releases/tag/v7.59.0">2025-06-28</a></br><p>🪱
feat: support deep equality checking with circular references (<a
class="issue-link js-issue-link" data-error-text="Failed to load title"
data-id="3176586583" data-permission-text="Title is private"
data-url="react-hook-form/react-hook-form#12914"
data-hovercard-type="pull_request"
data-hovercard-url="/react-hook-form/react-hook-form/pull/12914/hovercard"
href="https://redirect.github.com/react-hook-form/react-hook-form/pull/12914">#12914</a>)<br>
🐞 fix <a class="issue-link js-issue-link" data-error-text="Failed to
load title" data-id="3162019046" data-permission-text="Title is private"
data-url="react-hook-form/react-hook-form#12900"
data-hovercard-type="issue"
data-hovercard-url="/react-hook-form/react-hook-form/issues/12900/hovercard"
href="https://redirect.github.com/react-hook-form/react-hook-form/issues/12900">#12900</a> issue
with formData reference clone (<a class="issue-link js-issue-link"
data-error-text="Failed to load title" data-id="3164608853"
data-permission-text="Title is private"
data-url="react-hook-form/react-hook-form#12906"
data-hovercard-type="pull_request"
data-hovercard-url="/react-hook-form/react-hook-form/pull/12906/hovercard"
href="https://redirect.github.com/react-hook-form/react-hook-form/pull/12906">#12906</a>)<br>
🐞 fix <a class="issue-link js-issue-link" data-error-text="Failed to
load title" data-id="3124599969" data-permission-text="Title is private"
data-url="react-hook-form/react-hook-form#12873"
data-hovercard-type="issue"
data-hovercard-url="/react-hook-form/react-hook-form/issues/12873/hovercard"
href="https://redirect.github.com/react-hook-form/react-hook-form/issues/12873">#12873</a> issue
with undefined value for submit data (<a class="issue-link
js-issue-link" data-error-text="Failed to load title"
data-id="3164563082" data-permission-text="Title is private"
data-url="react-hook-form/react-hook-form#12905"
data-hovercard-type="pull_request"
data-hovercard-url="/react-hook-form/react-hook-form/pull/12905/hovercard"
href="https://redirect.github.com/react-hook-form/react-hook-form/pull/12905">#12905</a>)<br>
🐞 fix case when useWatch accept object variable param (<a
class="issue-link js-issue-link" data-error-text="Failed to load title"
data-id="3157299182" data-permission-text="Title is private"
data-url="react-hook-form/react-hook-form#12897"
data-hovercard-type="pull_request"
data-hovercard-url="/react-hook-form/react-hook-form/pull/12897/hovercard"
href="https://redirect.github.com/react-hook-form/react-hook-form/pull/12897">#12897</a>)<br>
🐞 fix: typo in UseFormSubscribe and missing event type for callback data
in subscribe (<a class="issue-link js-issue-link"
data-error-text="Failed to load title" data-id="3163748029"
data-permission-text="Title is private"
data-url="react-hook-form/react-hook-form#12904"
data-hovercard-type="pull_request"
data-hovercard-url="/react-hook-form/react-hook-form/pull/12904/hovercard"
href="https://redirect.github.com/react-hook-form/react-hook-form/pull/12904">#12904</a>)<br>
Revert "⌨️ rename to UseFormResetFieldOptions for type consistency" (<a
class="issue-link js-issue-link" data-error-text="Failed to load title"
data-id="3165853766" data-permission-text="Title is private"
data-url="react-hook-form/react-hook-form#12907"
data-hovercard-type="pull_request"
data-hovercard-url="/react-hook-form/react-hook-form/pull/12907/hovercard"
href="https://redirect.github.com/react-hook-form/react-hook-form/pull/12907">#12907</a>)</p>
<p>thanks to <a class="user-mention notranslate"
data-hovercard-type="user"
data-hovercard-url="/users/aspirisen/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://redirect.github.com/aspirisen">@ aspirisen</a> <a
class="user-mention notranslate" data-hovercard-type="user"
data-hovercard-url="/users/n8pjl/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://redirect.github.com/n8pjl">@ n8pjl</a> <a
class="user-mention notranslate" data-hovercard-type="user"
data-hovercard-url="/users/SKOLZ/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://redirect.github.com/SKOLZ">@ SKOLZ</a> <a
class="user-mention notranslate" data-hovercard-type="user"
data-hovercard-url="/users/pushys/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://redirect.github.com/pushys">@ pushys</a> &amp; <a
class="user-mention notranslate" data-hovercard-type="user"
data-hovercard-url="/users/candymask0712/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://redirect.github.com/candymask0712">@ candymask0712</a></p>
      </li>
      <li>
<b>7.58.1</b> - <a
href="https://redirect.github.com/react-hook-form/react-hook-form/releases/tag/v7.58.1">2025-06-17</a></br><p>🔧
check window.crypto undefined (<a class="issue-link js-issue-link"
data-error-text="Failed to load title" data-id="3153410474"
data-permission-text="Title is private"
data-url="react-hook-form/react-hook-form#12893"
data-hovercard-type="pull_request"
data-hovercard-url="/react-hook-form/react-hook-form/pull/12893/hovercard"
href="https://redirect.github.com/react-hook-form/react-hook-form/pull/12893">#12893</a>)</p>
      </li>
    </ul>
from <a
href="https://redirect.github.com/react-hook-form/react-hook-form/releases">react-hook-form
GitHub release notes</a>
  </details>
</details>

---

> [!IMPORTANT]
>
> - Check the changes in this PR to ensure they won't cause issues with
your project.
> - This PR was automatically created by Snyk using the credentials of a
real user.

---

**Note:** _You are seeing this because you or someone else with access
to this repository has authorized Snyk to open upgrade PRs._

**For more information:** <img
src="https://api.segment.io/v1/pixel/track?data=eyJ3cml0ZUtleSI6InJyWmxZcEdHY2RyTHZsb0lYd0dUcVg4WkFRTnNCOUEwIiwiYW5vbnltb3VzSWQiOiI5YmFkOWQwOS0yOWQxLTQxMzAtOGQyZS01NWQyNGJkYzIxMTkiLCJldmVudCI6IlBSIHZpZXdlZCIsInByb3BlcnRpZXMiOnsicHJJZCI6IjliYWQ5ZDA5LTI5ZDEtNDEzMC04ZDJlLTU1ZDI0YmRjMjExOSJ9fQ=="
width="0" height="0"/>

> - 🧐 [View latest project
report](https://app.snyk.io/org/kagent/project/3a1ab099-8f8f-43a5-81e6-e07ff34c96dc?utm_source&#x3D;github&amp;utm_medium&#x3D;referral&amp;page&#x3D;upgrade-pr)
> - 📜 [Customise PR
templates](https://docs.snyk.io/scan-using-snyk/pull-requests/snyk-fix-pull-or-merge-requests/customize-pr-templates?utm_source=&utm_content=fix-pr-template)
> - 🛠 [Adjust upgrade PR
settings](https://app.snyk.io/org/kagent/project/3a1ab099-8f8f-43a5-81e6-e07ff34c96dc/settings/integration?utm_source&#x3D;github&amp;utm_medium&#x3D;referral&amp;page&#x3D;upgrade-pr)
> - 🔕 [Ignore this dependency or unsubscribe from future upgrade
PRs](https://app.snyk.io/org/kagent/project/3a1ab099-8f8f-43a5-81e6-e07ff34c96dc/settings/integration?pkg&#x3D;react-hook-form&amp;utm_source&#x3D;github&amp;utm_medium&#x3D;referral&amp;page&#x3D;upgrade-pr#auto-dep-upgrades)

[//]: #
'snyk:metadata:{"customTemplate":{"variablesUsed":[],"fieldsUsed":[]},"dependencies":[{"name":"react-hook-form","from":"7.58.1","to":"7.61.0"}],"env":"prod","hasFixes":false,"isBreakingChange":false,"isMajorUpgrade":false,"issuesToFix":[],"prId":"9bad9d09-29d1-4130-8d2e-55d24bdc2119","prPublicId":"9bad9d09-29d1-4130-8d2e-55d24bdc2119","packageManager":"npm","priorityScoreList":[],"projectPublicId":"3a1ab099-8f8f-43a5-81e6-e07ff34c96dc","projectUrl":"https://app.snyk.io/org/kagent/project/3a1ab099-8f8f-43a5-81e6-e07ff34c96dc?utm_source=github&utm_medium=referral&page=upgrade-pr","prType":"upgrade","templateFieldSources":{"branchName":"default","commitMessage":"default","description":"default","title":"default"},"templateVariants":[],"type":"auto","upgrade":[],"upgradeInfo":{"versionsDiff":4,"publishedDate":"2025-07-23T23:20:49.867Z"},"vulns":[]}'

---------

Signed-off-by: Peter Jausovec <[email protected]>
Co-authored-by: snyk-bot <[email protected]>
peterj added a commit to kagent-dev/kagent that referenced this pull request Aug 17, 2025
![snyk-top-banner](https://res.cloudinary.com/snyk/image/upload/r-d/scm-platform/snyk-pull-requests/pr-banner-default.svg)


<h3>Snyk has created this PR to upgrade react-hook-form from 7.61.0 to
7.61.1.</h3>

:information_source: Keep your dependencies up-to-date. This makes it
easier to fix existing vulnerabilities and to more quickly identify and
fix newly disclosed vulnerabilities when they affect your project.

<hr/>


- The recommended version is **1 version** ahead of your current
version.

- The recommended version was released **23 days ago**.



<details>
<summary><b>Release notes</b></summary>
<br/>
  <details>
    <summary>Package name: <b>react-hook-form</b></summary>
    <ul>
      <li>
<b>7.61.1</b> - <a
href="https://redirect.github.com/react-hook-form/react-hook-form/releases/tag/v7.61.1">2025-07-24</a></br><p>Revert
"⌨️ fix: watch return type based on defaultValue (<a class="issue-link
js-issue-link" data-error-text="Failed to load title"
data-id="3156326445" data-permission-text="Title is private"
data-url="react-hook-form/react-hook-form#12896"
data-hovercard-type="pull_request"
data-hovercard-url="/react-hook-form/react-hook-form/pull/12896/hovercard"
href="https://redirect.github.com/react-hook-form/react-hook-form/pull/12896">#12896</a>)"</p>
      </li>
      <li>
<b>7.61.0</b> - <a
href="https://redirect.github.com/react-hook-form/react-hook-form/releases/tag/v7.61.0">2025-07-23</a></br><p>🧮
feat: compute prop for useWatch subscription (<a class="issue-link
js-issue-link" data-error-text="Failed to load title"
data-id="2761362352" data-permission-text="Title is private"
data-url="react-hook-form/react-hook-form#12503"
data-hovercard-type="pull_request"
data-hovercard-url="/react-hook-form/react-hook-form/pull/12503/hovercard"
href="https://redirect.github.com/react-hook-form/react-hook-form/pull/12503">#12503</a>)</p>
<ul>
<li>subscribe to the entire form but only return updated value with
certain condition</li>
</ul>
<div class="highlight highlight-source-tsx notranslate position-relative
overflow-auto" data-snippet-clipboard-copy-content="type FormValue = {
  test: string;
}

const watchedValue = useWatch({
  control: methods.control,
  compute: (data: FormValue) =&gt; {
    if (data.test?.length) {
      return data.test;
    }

    return '';
  },
});"><pre><span class="pl-k">type</span> <span
class="pl-smi">FormValue</span> <span class="pl-c1">=</span> <span
class="pl-kos">{</span>
<span class="pl-c1">test</span>: <span class="pl-smi">string</span><span
class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">const</span> <span class="pl-s1">watchedValue</span>
<span class="pl-c1">=</span> <span class="pl-en">useWatch</span><span
class="pl-kos">(</span><span class="pl-kos">{</span>
<span class="pl-c1">control</span>: <span
class="pl-s1">methods</span><span class="pl-kos">.</span><span
class="pl-c1">control</span><span class="pl-kos">,</span>
<span class="pl-en">compute</span>: <span class="pl-kos">(</span><span
class="pl-s1">data</span>: <span class="pl-smi">FormValue</span><span
class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span
class="pl-kos">{</span>
<span class="pl-k">if</span> <span class="pl-kos">(</span><span
class="pl-s1">data</span><span class="pl-kos">.</span><span
class="pl-c1">test</span><span class="pl-kos">?.</span><span
class="pl-c1">length</span><span class="pl-kos">)</span> <span
class="pl-kos">{</span>
<span class="pl-k">return</span> <span class="pl-s1">data</span><span
class="pl-kos">.</span><span class="pl-c1">test</span><span
class="pl-kos">;</span>
    <span class="pl-kos">}</span>

<span class="pl-k">return</span> <span class="pl-s">''</span><span
class="pl-kos">;</span>
  <span class="pl-kos">}</span><span class="pl-kos">,</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span
class="pl-kos">;</span></pre></div>
<ul>
<li>subscribe to a specific form value state</li>
</ul>
<div class="highlight highlight-source-tsx notranslate position-relative
overflow-auto" data-snippet-clipboard-copy-content="type FormValue = {
  test: string;
}

const watchedValue = useWatch({
  control: methods.control,
  name: 'test',
  compute: (data: string) =&gt; {
      return data.length &gt; 3 ? data : '';
  },
});"><pre><span class="pl-k">type</span> <span
class="pl-smi">FormValue</span> <span class="pl-c1">=</span> <span
class="pl-kos">{</span>
<span class="pl-c1">test</span>: <span class="pl-smi">string</span><span
class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">const</span> <span class="pl-s1">watchedValue</span>
<span class="pl-c1">=</span> <span class="pl-en">useWatch</span><span
class="pl-kos">(</span><span class="pl-kos">{</span>
<span class="pl-c1">control</span>: <span
class="pl-s1">methods</span><span class="pl-kos">.</span><span
class="pl-c1">control</span><span class="pl-kos">,</span>
<span class="pl-c1">name</span>: <span class="pl-s">'test'</span><span
class="pl-kos">,</span>
<span class="pl-en">compute</span>: <span class="pl-kos">(</span><span
class="pl-s1">data</span>: <span class="pl-smi">string</span><span
class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span
class="pl-kos">{</span>
<span class="pl-k">return</span> <span class="pl-s1">data</span><span
class="pl-kos">.</span><span class="pl-c1">length</span> <span
class="pl-c1">&gt;</span> <span class="pl-c1">3</span> ? <span
class="pl-s1">data</span> : <span class="pl-s">''</span><span
class="pl-kos">;</span>
  <span class="pl-kos">}</span><span class="pl-kos">,</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span
class="pl-kos">;</span></pre></div>
<p>👨‍🔧 trigger watch callbacks in response to value changes only (<a
class="issue-link js-issue-link" data-error-text="Failed to load title"
data-id="3210030061" data-permission-text="Title is private"
data-url="react-hook-form/react-hook-form#12945"
data-hovercard-type="pull_request"
data-hovercard-url="/react-hook-form/react-hook-form/pull/12945/hovercard"
href="https://redirect.github.com/react-hook-form/react-hook-form/pull/12945">#12945</a>)<br>
🙏 track name with setValue subscription callbacks (<a class="issue-link
js-issue-link" data-error-text="Failed to load title"
data-id="3210194804" data-permission-text="Title is private"
data-url="react-hook-form/react-hook-form#12946"
data-hovercard-type="pull_request"
data-hovercard-url="/react-hook-form/react-hook-form/pull/12946/hovercard"
href="https://redirect.github.com/react-hook-form/react-hook-form/pull/12946">#12946</a>)<br>
⌨️ fix: watch return type based on defaultValue (<a class="issue-link
js-issue-link" data-error-text="Failed to load title"
data-id="3156326445" data-permission-text="Title is private"
data-url="react-hook-form/react-hook-form#12896"
data-hovercard-type="pull_request"
data-hovercard-url="/react-hook-form/react-hook-form/pull/12896/hovercard"
href="https://redirect.github.com/react-hook-form/react-hook-form/pull/12896">#12896</a>)<br>
🐞 fix <a class="issue-link js-issue-link" data-error-text="Failed to
load title" data-id="3226443079" data-permission-text="Title is private"
data-url="react-hook-form/react-hook-form#12959"
data-hovercard-type="issue"
data-hovercard-url="/react-hook-form/react-hook-form/issues/12959/hovercard"
href="https://redirect.github.com/react-hook-form/react-hook-form/issues/12959">#12959</a>
subscribe with latest defaultValues <a class="issue-link js-issue-link"
data-error-text="Failed to load title" data-id="3226946310"
data-permission-text="Title is private"
data-url="react-hook-form/react-hook-form#12961"
data-hovercard-type="pull_request"
data-hovercard-url="/react-hook-form/react-hook-form/pull/12961/hovercard"
href="https://redirect.github.com/react-hook-form/react-hook-form/pull/12961">#12961</a><br>
🐞 fix: handle explicit "multipart/form-data" encType in Form Component
(<a class="issue-link js-issue-link" data-error-text="Failed to load
title" data-id="3212769870" data-permission-text="Title is private"
data-url="react-hook-form/react-hook-form#12948"
data-hovercard-type="pull_request"
data-hovercard-url="/react-hook-form/react-hook-form/pull/12948/hovercard"
href="https://redirect.github.com/react-hook-form/react-hook-form/pull/12948">#12948</a>)<br>
🐞 fix(build): Remove React wildcard import to resolve ESM build issues
(<a class="issue-link js-issue-link" data-error-text="Failed to load
title" data-id="3206776702" data-permission-text="Title is private"
data-url="react-hook-form/react-hook-form#12942"
data-hovercard-type="pull_request"
data-hovercard-url="/react-hook-form/react-hook-form/pull/12942/hovercard"
href="https://redirect.github.com/react-hook-form/react-hook-form/pull/12942">#12942</a>)<br>
🦭 chore: improve exclude patterns (<a class="issue-link js-issue-link"
data-error-text="Failed to load title" data-id="3202497669"
data-permission-text="Title is private"
data-url="react-hook-form/react-hook-form#12935"
data-hovercard-type="pull_request"
data-hovercard-url="/react-hook-form/react-hook-form/pull/12935/hovercard"
href="https://redirect.github.com/react-hook-form/react-hook-form/pull/12935">#12935</a>)<br>
🐿️ chore: remove unused omit function (<a class="issue-link
js-issue-link" data-error-text="Failed to load title"
data-id="3225961191" data-permission-text="Title is private"
data-url="react-hook-form/react-hook-form#12958"
data-hovercard-type="pull_request"
data-hovercard-url="/react-hook-form/react-hook-form/pull/12958/hovercard"
href="https://redirect.github.com/react-hook-form/react-hook-form/pull/12958">#12958</a>)</p>
<p>Big thanks to <a class="user-mention notranslate"
data-hovercard-type="user" data-hovercard-url="/users/joshkel/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://redirect.github.com/joshkel">@ joshkel</a> for helping
with some of the subscription bugs! and also <a class="user-mention
notranslate" data-hovercard-type="user"
data-hovercard-url="/users/kamja44/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://redirect.github.com/kamja44">@ kamja44</a>, <a
class="user-mention notranslate" data-hovercard-type="user"
data-hovercard-url="/users/mrazauskas/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://redirect.github.com/mrazauskas">@ mrazauskas</a>, <a
class="user-mention notranslate" data-hovercard-type="user"
data-hovercard-url="/users/codepunkt/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://redirect.github.com/codepunkt">@ codepunkt</a>, <a
class="user-mention notranslate" data-hovercard-type="user"
data-hovercard-url="/users/afontcu/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://redirect.github.com/afontcu">@ afontcu</a> and <a
class="user-mention notranslate" data-hovercard-type="user"
data-hovercard-url="/users/rururux/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://redirect.github.com/rururux">@ rururux</a></p>
      </li>
    </ul>
from <a
href="https://redirect.github.com/react-hook-form/react-hook-form/releases">react-hook-form
GitHub release notes</a>
  </details>
</details>

---

> [!IMPORTANT]
>
> - Check the changes in this PR to ensure they won't cause issues with
your project.
> - This PR was automatically created by Snyk using the credentials of a
real user.

---

**Note:** _You are seeing this because you or someone else with access
to this repository has authorized Snyk to open upgrade PRs._

**For more information:** <img
src="https://api.segment.io/v1/pixel/track?data=eyJ3cml0ZUtleSI6InJyWmxZcEdHY2RyTHZsb0lYd0dUcVg4WkFRTnNCOUEwIiwiYW5vbnltb3VzSWQiOiJjMTY2MTdjMi0yNDBkLTRkZDItOTRiZC01ZjZhOGI1MjY1OGQiLCJldmVudCI6IlBSIHZpZXdlZCIsInByb3BlcnRpZXMiOnsicHJJZCI6ImMxNjYxN2MyLTI0MGQtNGRkMi05NGJkLTVmNmE4YjUyNjU4ZCJ9fQ=="
width="0" height="0"/>

> - 🧐 [View latest project
report](https://app.snyk.io/org/kagent/project/3a1ab099-8f8f-43a5-81e6-e07ff34c96dc?utm_source&#x3D;github&amp;utm_medium&#x3D;referral&amp;page&#x3D;upgrade-pr)
> - 📜 [Customise PR
templates](https://docs.snyk.io/scan-using-snyk/pull-requests/snyk-fix-pull-or-merge-requests/customize-pr-templates?utm_source=&utm_content=fix-pr-template)
> - 🛠 [Adjust upgrade PR
settings](https://app.snyk.io/org/kagent/project/3a1ab099-8f8f-43a5-81e6-e07ff34c96dc/settings/integration?utm_source&#x3D;github&amp;utm_medium&#x3D;referral&amp;page&#x3D;upgrade-pr)
> - 🔕 [Ignore this dependency or unsubscribe from future upgrade
PRs](https://app.snyk.io/org/kagent/project/3a1ab099-8f8f-43a5-81e6-e07ff34c96dc/settings/integration?pkg&#x3D;react-hook-form&amp;utm_source&#x3D;github&amp;utm_medium&#x3D;referral&amp;page&#x3D;upgrade-pr#auto-dep-upgrades)

[//]: #
'snyk:metadata:{"customTemplate":{"variablesUsed":[],"fieldsUsed":[]},"dependencies":[{"name":"react-hook-form","from":"7.61.0","to":"7.61.1"}],"env":"prod","hasFixes":false,"isBreakingChange":false,"isMajorUpgrade":false,"issuesToFix":[],"prId":"c16617c2-240d-4dd2-94bd-5f6a8b52658d","prPublicId":"c16617c2-240d-4dd2-94bd-5f6a8b52658d","packageManager":"npm","priorityScoreList":[],"projectPublicId":"3a1ab099-8f8f-43a5-81e6-e07ff34c96dc","projectUrl":"https://app.snyk.io/org/kagent/project/3a1ab099-8f8f-43a5-81e6-e07ff34c96dc?utm_source=github&utm_medium=referral&page=upgrade-pr","prType":"upgrade","templateFieldSources":{"branchName":"default","commitMessage":"default","description":"default","title":"default"},"templateVariants":[],"type":"auto","upgrade":[],"upgradeInfo":{"versionsDiff":1,"publishedDate":"2025-07-24T12:22:03.373Z"},"vulns":[]}'

Co-authored-by: snyk-bot <[email protected]>
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.

useWatch computed value performance

10 participants