preact.render does not return component instance
See original GitHub issueThe return value doesn’t appear to be documented for either ReactDOM.render or preact.render, but with ReactDOM an instance of the component can be returned.
Example code via StackOverflow comment:
var Hello = React.createClass({
render: function() {
return (this.state) ? <div>Hello {this.state.name}</div> : null;
}
});
var component = ReactDOM.render(<Hello/>, document.getElementById('container'));
component.setState({name: "World"});
setTimeout(function(){
component.setState({name: "StackOverFlow"});
}, 1000);
This does not work with Preact; the return value of preact.render
appears to be the real DOM rather than the virtual one. Is this intentional?
[I’ll note that using React in this way appears to be frowned upon, at least in that StackOverflow thread I found. But imo it could be handy to have outside access to components, especially with small/store-less apps.]
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
API Reference | Preact
The render function is passed the component's current props and state, and should return a Virtual DOM Element (typically a JSX "element"), an...
Read more >API Reference | Preact: Fast 3kb React alternative with the ...
The render() function is required for all components. It can inspect the props and state of the component, and should return a Preact...
Read more >Components | Preact
Components represent the basic building block in Preact. They are fundamental in making it easy to build complex UIs from little building blocks....
Read more >Components - Preact
Class components are created by extending Preact's Component base class. In the example below, notice how render() takes props as its input and...
Read more >Web Components | Preact
When rendering static HTML using preact-render-to-string ("SSR"), complex property values like the object above are not automatically serialized. They are ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
ah - you should use a ref on the root. That will work in both libs:
@developit D’oh! I had checked preact-compat for this, and even found that method, but somehow completely missed the obvious
&& out._component
part that must have been right under my nose 😦+1 for wontfixing this — <del>I’m content doing my own
._component
lookup even if it’s a small maintenance concern should preact ever change its internals there</del> ☝︎☝︎☝︎ ref thing above 💯 .