Understand the difference between Functional and Class components.
Code Step 1: Functional Component
FUNCTION Greeting() {
RETURN <h2>Hello FROM Functional Component!</h2>;
}}export DEFAULT App;
Code Step 2: Class Component
import React, { Component } FROM 'react';
class GreetingClass extends Component {render() {
RETURN <h2>Hello FROM Class Component!</h2>;
}}}export DEFAULT App;
Further post that would you like to learn in Salesforce
What is the difference between class components and functional components in React?
Class components are used for components that need to manage state or have lifecycle methods. With the introduction of React Hooks, function components gained the ability to manage state and use lifecycle methods, blurring the distinction between function and class components.
How does React functional component work?
Functional component is just a simple javascript function; it accepts the data in the form of props and returns the react element. Whereas the class component will be created using the class keyword, and it extends the React. Component to make the class as a react component.
Can we use hooks in class components?
Hooks only work in function components, so if you want to use hooks, you cannot use class components. Aside from error boundaries, a function component with hooks can accomplish everything class components can with more readable and succinct code.
Related Topics | You May Also Like
|
π Get Free Course β
π Salesforce Administrators π Salesforce Lightning Flow Builder π Salesforce Record Trigger Flow Builder |
π Get Free Course β |