Skip to content

Commit b816328

Browse files
authored
Import useEffect normally (#5501)
The `Layout` isn't wrapped in an ErrorBoundary, and this particular usage of `useEffect` seems to trip up HMR in the sandbox when replacing the app code. Instead, use a direct named import, which might be handled more nicely in vite.
1 parent 7b4df17 commit b816328

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

reflex/.templates/jinja/web/pages/_app.js.jinja2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function AppWrap({children}) {
3434

3535

3636
export function Layout({children}) {
37-
React.useEffect(() => {
37+
useEffect(() => {
3838
// Make contexts and state objects available globally for dynamic eval'd components
3939
let windowImports = {
4040
{% for library_alias, library_path in window_libraries %}

reflex/compiler/compiler.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ def _apply_common_imports(
3737
imports: dict[str, list[ImportVar]],
3838
):
3939
imports.setdefault("@emotion/react", []).append(ImportVar("jsx"))
40-
imports.setdefault("react", []).append(ImportVar("Fragment"))
40+
imports.setdefault("react", []).extend(
41+
[ImportVar("Fragment"), ImportVar("useEffect")],
42+
)
4143

4244

4345
def _compile_document_root(root: Component) -> str:

0 commit comments

Comments
 (0)