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.

Initial state for function vs class based components

See original GitHub issue

Likely not an issue but my incomplete understanding. By the way is there a better place for asking questions?

I am trying to implement custom (LemonadeJS) components as ES6 classes, and realized attributes are not being read from the tag. Take this example from a parent component markup:

<Hello title="The very best of 2022" />

This renders fine (copied from one of the library examples):

function Hello() {
    // Get the attributes from the tag
    let self = this;
 
    // Title and year are declared in the parent template
    let template = `<h1>{{self.title}} {{self.year}}</h1>`;
 
    return lemonade.element(template, self);
}

This does not (self.title renders empty):

class Hello extends lemonade.component {

    render() {
        return lemonade.element(`<h1>{{self.title}} {{self.year}}</h1>`, this);
    }

}

Except from the initial value the parent tries to set, everything seems to work fine with the class-based Hello component.

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:20 (20 by maintainers)

github_iconTop GitHub Comments

1reaction
hodewarecommented, Dec 27, 2022

That’s correct.

1reaction
hodewarecommented, Dec 27, 2022

But, @ref still a problem which only be fixed on version 3.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React State in Class and Function Components
Initializing state​​ In class components, there are two ways to initialize state — in a constructor function or as a Class property. Constructor...
Read more >
Understanding Functional Components vs. Class ... - Twilio
To use state variables in a functional component, we need to use useState Hook, which takes an argument of initial state. In this...
Read more >
React Class Component vs Functional Component - Telerik
The class component, a stateful/container component, is a regular ES6 class that extends the component class of the React library. It is called ......
Read more >
Functional vs Class-Components in React | Quick Guide
In this section, we will differentiate based on features as that class provide devs with such functionality as lifecycle and setState(). Methods ...
Read more >
React: class components vs function components
The issue with class based components and the driving reason why the React team went towards functional components was for better abstractions.
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