Comments (5)
@sylsaint React's reuse of the DOM node here is expected given the reconciliation algorithm's specifications and constraints, and the way you've structured your JSX. You're returning the same VDOM structure each time with a <button>
in the same place, but only the attributes on it are different.
The docs go into a lot of depth on this sort of scenario https://react.dev/learn/preserving-and-resetting-state
from react.
The corresponding no-framework code:
<form><button type="button">Click me</button></form>
document.querySelector("button").addEventListener("click", e => { e.target.setAttribute("type", "submit"); });
will do the exact same thing and also fire the submit event. So isn't this the intended behavior? If it's not what you want, your proposed workaround with key
is probably the cleanest.
from react.
Hm yea this seems confusing but matches how the DOM works. I think I'll close this.
from react.
@nmain Your code is based on the the same DOM node, it's ok. But in react they are actually different node, during render process, react reuse last DOM node, just modify its properties.
from react.
@gaearon Yes, it's confusing. But actually it's caused by react that reused the same DOM node for different buttons.
from react.
Related Issues (20)
- Bug: ios elastically scrolls to a certain distance, causing some elements in the fixed content area to disappear? HOT 1
- Bug: support `fetchPriority` in camel-case on DOM nodes.
- Bug: Safari gets stuck when listening to "wheel" event and element size changes HOT 1
- Bug: moving item in list resets scroll when item has `key` prop HOT 4
- Bug: react.dev tutorial-tic-tac-toe sample project errors out in modern node versions HOT 11
- Feature request: TODO task HOT 1
- Could you please add a license file to the client-only package? HOT 8
- [DevTools Bug]: TypeError: Cannot read properties of undefined (reading 'forEach') HOT 10
- bypass progressive loading for the CSS HOT 5
- Bug: hydration fails when using Promise values with React Server Components
- Bug: Re-rendering dynamically nested createElement() unmounts children
- React Way to Make Immediate Changes on DOM HOT 1
- [React: re-render]: On changing search value: it re-render the whole component HOT 8
- Bug: some /public resources not served when proxy is enabled in manifest. HOT 2
- Bug: No apparent way to debug setupProxy.js HOT 1
- Bug: useEffect not firing when depending on hook value HOT 2
- Bug: HOT 1
- Anisha wants to pay 0 USD to have this issue fixed
- Bug: Rendering Twice in StrictMode with useSyncExternalStore Official Example HOT 1
- Bug: script inside script render with SSR + renderToPipeableStream
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react.