Skip to content

Commit 3ba74dd

Browse files
committed
ah we need to call var_name
1 parent 86b32f4 commit 3ba74dd

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

reflex/compiler/templates.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,10 @@ def context_template(
373373
"""
374374
initial_state = initial_state or {}
375375
state_contexts_str = "".join(
376-
[f"{state_name}: createContext(null)," for state_name in initial_state]
376+
[
377+
f"{format_state_name(state_name)}: createContext(null),"
378+
for state_name in initial_state
379+
]
377380
)
378381

379382
state_str = (
@@ -424,17 +427,18 @@ def context_template(
424427
)
425428

426429
state_reducer_str = "\n".join(
427-
rf'const [{state_name}, dispatch_{state_name}] = useReducer(applyDelta, initialState["{state_name}"])'
430+
rf'const [{format_state_name(state_name)}, dispatch_{format_state_name(state_name)}] = useReducer(applyDelta, initialState["{state_name}"])'
428431
for state_name in initial_state
429432
)
430433

431434
create_state_contexts_str = "\n".join(
432-
rf"createElement(StateContexts.{state_name},{{value: {state_name}}},"
435+
rf"createElement(StateContexts.{format_state_name(state_name)},{{value: {format_state_name(state_name)}}},"
433436
for state_name in initial_state
434437
)
435438

436439
dispatchers_str = "\n".join(
437-
f'"{state_name}": dispatch_{state_name},' for state_name in initial_state
440+
f'"{state_name}": dispatch_{format_state_name(state_name)},'
441+
for state_name in initial_state
438442
)
439443

440444
return rf"""import {{ createContext, useContext, useMemo, useReducer, useState, createElement, useEffect }} from "react"
@@ -443,7 +447,7 @@ def context_template(
443447
444448
export const initialState = {"{}" if initial_state else json_dumps(initial_state)}
445449
446-
export const defaultColorMode = { default_color_mode }
450+
export const defaultColorMode = {default_color_mode}
447451
export const ColorModeContext = createContext(null);
448452
export const UploadFilesContext = createContext(null);
449453
export const DispatchContext = createContext(null);
@@ -830,16 +834,5 @@ def render(self, **kwargs) -> str:
830834
# Code to render StatefulComponent to an external file to be shared
831835
STATEFUL_COMPONENTS = TemplateFunction(_stateful_components_template)
832836

833-
# Sitemap config file.
834-
SITEMAP_CONFIG = "module.exports = {config}".format
835-
836837
# Code to render the root stylesheet.
837838
STYLE = TemplateFunction(_styles_template)
838-
839-
# Template containing some macros used in the web pages.
840-
MACROS = TemplateFunction(
841-
lambda **kwargs: _render_hooks(
842-
kwargs.get("hooks", {}),
843-
kwargs.get("memo", None),
844-
)
845-
)

reflex/components/markdown/markdown.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,12 +422,12 @@ def _get_component_map_name(self) -> str:
422422

423423
def _get_custom_code(self) -> str | None:
424424
hooks = {}
425-
from reflex.compiler.templates import MACROS
425+
from reflex.compiler.templates import _render_hooks
426426

427427
for _component in self.component_map.values():
428428
comp = _component(_MOCK_ARG)
429429
hooks.update(comp._get_all_hooks())
430-
formatted_hooks = MACROS.module.renderHooks(hooks) # pyright: ignore [reportAttributeAccessIssue]
430+
formatted_hooks = _render_hooks(hooks)
431431
return f"""
432432
function {self._get_component_map_name()} () {{
433433
{formatted_hooks}

0 commit comments

Comments
 (0)