You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I write component with default export and without name like: export default function(){...} the component is getting unmounted/mounted instead of just rerendered. It is different to the default export with a name like export default function Foo(){...}. The name is not important. It happens only in watch and serve mode.
import{useState,useEffect}from'react';importTestfrom"./test.jsx"exportfunctionApp(){const[foo,setFoo]=useState();console.debug("Rendering...")// every second change state randomlyuseEffect(function(){constinterval=setInterval(()=>Promise.resolve().then(_=>setFoo(Math.random())),1000)return()=>clearInterval(interval)},[])return(<Test/>)}
test.jsx
import{useEffect}from'react';exportdefaultfunction(){// This just prints when it is mounting/unmountinguseEffect(()=>{console.log("Test mounting");return()=>console.log("Test unmounting")},[]);return<spanstyle={{color: "red"}}>Lorem ipsum</span>}
🌍 Your Environment
Software
Version(s)
Node
v23.6.0
npm/Yarn
npm - 11.0.0
Operating System
win11
The text was updated successfully, but these errors were encountered:
🐛 bug report
If I write component with default export and without name like:
export default function(){...}
the component is getting unmounted/mounted instead of just rerendered. It is different to the default export with a name likeexport default function Foo(){...}
. The name is not important. It happens only in watch and serve mode.🎛 Configuration (.babelrc, package.json, cli command)
🤔 Expected Behavior
It should be the same like with name.
In the following code sample I expect to see only
Test mounting
once and then repeating ofRendering...
😯 Current Behavior
In watch and serve it differs from the named function.
In the sample code I am getting repeatedly:
Rendering...
Test unmounting
Test mounting
💁 Possible Solution
🔦 Context
💻 Code Sample
index.html
index.jsx
app.jsx
test.jsx
🌍 Your Environment
The text was updated successfully, but these errors were encountered: