MCPcopy Index your code
hub / github.com/reactive-python/reactpy / use_debug_value

Function use_debug_value

src/py/reactpy/reactpy/core/hooks.py:180–208  ·  view source on GitHub ↗

Log debug information when the given message changes. .. note:: This hook only logs if :data:`~reactpy.config.REACTPY_DEBUG_MODE` is active. Unlike other hooks, a message is considered to have changed if the old and new values are ``!=``. Because this comparison is performed on

(
    message: Any | Callable[[], Any],
    dependencies: Sequence[Any] | ellipsis | None = ...,
)

Source from the content-addressed store, hash-verified

178
179
180def use_debug_value(
181 message: Any | Callable[[], Any],
182 dependencies: Sequence[Any] | ellipsis | None = ...,
183) -> None:
184 """Log debug information when the given message changes.
185
186 .. note::
187 This hook only logs if :data:`~reactpy.config.REACTPY_DEBUG_MODE` is active.
188
189 Unlike other hooks, a message is considered to have changed if the old and new
190 values are ``!=``. Because this comparison is performed on every render of the
191 component, it may be worth considering the performance cost in some situations.
192
193 Parameters:
194 message:
195 The value to log or a memoized function for generating the value.
196 dependencies:
197 Dependencies for the memoized function. The message will only be recomputed
198 if the identity of any value in the given sequence changes (i.e. their
199 :func:`id` is different). By default these are inferred based on local
200 variables that are referenced by the given function.
201 """
202 old: Ref[Any] = _use_const(lambda: Ref(object()))
203 memo_func = message if callable(message) else lambda: message
204 new = use_memo(memo_func, dependencies)
205
206 if REACTPY_DEBUG_MODE.current and old.current != new:
207 old.current = new
208 logger.debug(f"{current_hook().component} {new}")
209
210
211def create_context(default_value: _Type) -> Context[_Type]:

Callers

nothing calls this directly

Calls 4

RefClass · 0.90
current_hookFunction · 0.90
_use_constFunction · 0.85
use_memoFunction · 0.85

Tested by

no test coverage detected