-
Notifications
You must be signed in to change notification settings - Fork 48.5k
Components with children without DOM representation #2191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This was discussed (see #690 (comment) for example) and I think it is/was on React's roadmap. |
Sounds great, thank you! |
You can return
I'm not sure if I really undersand you. Composite classes (your own classes) by definition doesn't have a DOM representation, only |
I want to be able to return something that would work in a similar way to 'return null / noscript' (so practically no DOM representation), but would accept children and mount them. |
@freiksenet What you're asking for should still be to return multiple components. If you genuinely don't want them to be mounted into the DOM then you're using React components too much like OOP, which is not a good idea. React is only concerned with "views". |
I am making a library that are using react components as nodes in scenegraph canvas renderer https://github.com/freiksenet/react-kinetic. For scenegraph nodes that can have children, I want to return this children somehow from render, so they are mounted in react and their lifecycle methods trigger correctly, so that I can insert them into the scenegraph. https://github.com/freiksenet/react-kinetic/blob/master/src/KineticContainerMixin.js As you see currently I return null for terminal nodes, but I have to wrap children into spans. |
Ah yes, I see your point. But I don't think React (master branch) is well-suited to this at the moment, you can look at ReactART, it's a branch of React that works on SVG (or was it canvas) instead. Some dev probably has a more definitive answer for this. |
I have seen it and I have tried to model their approach at first. The problem is that it bases everything on ReactComponent, which lacks lots of features of ReactCompositeComponent that would be very nice to have, such as prop/context validation, context, lifecycle methods, lifecycle invariants. Unfortunately CompositeComponent doesn't separate all those parts very well and even the CompositeMixin is private and not exported. |
So yeah, the best solution would be to not do any hacks using DOM, but that requires composite component to be more decoupled from DOM and whose lifecycle and validation functionality is moved to mixins. |
I think @sebmarkbage 's work on decoupling mountComponent and other related methods might help with this issue. |
Kinda new to react, but can you do this by using
|
测试测试 |
1 similar comment
测试测试 |
In React 16 you can both return |
If I need a component that doesn't have a DOM representation, I can use render function that returns
<noscript>
. However recently I had to have a component without DOM representation, but that also has children, that I want to be mounted (so that their lifecycle methods trigger correctly). Unfortunately<noscript>
is not nestable, thus I had to return<span>
, which is not an ideal solution.Is there a way to do such thing without using
<span>
or<div>
? I know there are plans to replace<noscript>
solution with some 'null component'. Are there plans for 'null component' that can mount its children?The text was updated successfully, but these errors were encountered: