#2877·hooks

在 useUrlState 中增加是否启用参数

作者: javaxiu创建于 2025年11月24日更新于 2026年5月20日

Scenario: In a business scenario, we need to wrap a form, and this form may appear twice on a page (for example, both on the page and in a pop-up). If both are pushed to the state, it will be confusing. Therefore, we want the business to be able to optionally set this parameter to enable the pushState feature. When allowPushState = false, the effect is the same as react useState. Due to the limitations of react hooks, it is not allowed to write const [] = allowPushState ? useUrlState : useState. Additional wrapping will generate unnecessary code.