You can use ref to achieve this. This is very useful when you want to embed an object that is not wrapped by internal proxies within a proxy (such as storing DOM elements, File objects, and other unstructured data), but note that its changes will not be tracked. For more details and considerations, please refer to ref.
<input />
ElementsBy default, Reactive internally notifies changes asynchronously when state changes occur, to achieve batched updates for rendering optimization. If you want to disable this (for example, when used with <input />
elements, it may conflict with input method Composition events), you can set the sync
option to true
when using store.useSnapshot
to notify changes synchronously and avoid this issue.
This issue is difficult to avoid. The pseudo-code for Reactive's internal asynchronous notification is as follows, which allows you to intuitively experience this input method composition interruption phenomenon:
Additionally, if you are using React 18 or above, you can consider using the setGlobalNotifyInSync method introduced in version 0.3.0
to globally set the sync
option to true
to solve this issue. For more information, please refer to the setGlobalNotifyInSync documentation.
In almost all use cases, you may not encounter performance bottlenecks. However, when dealing with extremely large datasets (tens of millions of read operations or more), performance issues may become a challenge. This is mainly because when using Proxy
, each data access triggers the proxy's Getter
method, resulting in significant performance overhead during large-scale read operations. To avoid performance issues with large datasets, consider the following strategies:
useState
to separately manage large datasets that don't require reactive features.Proxy
.You can intuitively experience this performance difference through the following code in the console: