Error when render() is called before set hass(hass) (i.e. before this._hass is set)
See original GitHub issueThanks for giving us this super-awesome component!
There is an issue I wish to report along with a proposed solution.
I’m seeing that mostly the render()
method is called before set hass(hass)
.
This means that current()
(called from render) does not have this._hass
to work upon, so it throws an error, and prevents the rendering of the subsequent html in render()
.
On making these two changes, my testing has shown good results.
- In the beginning of
render()
:if (!this.config || !this._hass) return html``; // checking .config is also not a bad idea
- With above, we want
render()
to be called again whenset hass(hass)
is called. This can be done by watchingthis._hass
property, and the following getter will do that:static get properties() { return { _hass: {}, config: {}, }; }
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (8 by maintainers)
Top Results From Across the Web
React render() is being called before componentDidMount()
Here I get the quotes from the API and as soon as it finishes it set a variable in the state, then the...
Read more >Run Code in React Before Render - Dave Ceddia
This leads to errors like Cannot read property 'map' of undefined' when the component tries to render before the data is ready.
Read more >Rendering and Updating Data using Component Lifecycle ...
In this guide, we will learn several approaches to execute JavaScript after the render() method, including using initial render to fetch the ...
Read more >How and when to force a React component to re-render
In this demo, I built a clock that has a major problem: the time doesn't change after I first load the screen. Not...
Read more >Documentation - SolidJS · Reactive Javascript Library
A declarative, efficient and flexible JavaScript library for building user interfaces.
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
Thankyou, it has fixed my issue. Regards, Markus
Ok I’ve merged that into master. If you use HACS just pull master for now. I’ll bump the version and in a few days if you both (and I) have no issues I’ll do a release