Initial state for function vs class based components
See original GitHub issueLikely 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:
- Created 9 months ago
- Comments:20 (20 by maintainers)
Top 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 >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
That’s correct.
But, @ref still a problem which only be fixed on version 3.