question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error when render() is called before set hass(hass) (i.e. before this._hass is set)

See original GitHub issue

Thanks 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.

  1. In the beginning of render():
    if (!this.config || !this._hass) return html``;  // checking .config is also not a bad idea
    
  2. With above, we want render() to be called again when set hass(hass) is called. This can be done by watching this._hass property, and the following getter will do that:
    static get properties() {
      return {
        _hass: {},
        config: {},
      };
    }
    

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
markusg1234commented, Feb 20, 2022

Thankyou, it has fixed my issue. Regards, Markus

2reactions
DavidFW1960commented, Feb 20, 2022

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found