Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Interview question

What are the differences between Class and Functional components? Class और Functional components में क्या अंतर है?

Answer
AspectClassFunctional
SyntaxES6 classJavaScript function
Statethis.stateuseState hook
LifecycleLifecycle methodsuseEffect hook
This bindingRequiredNot needed
PerformanceHeavierLighter with hooks
// Class Component
class Welcome extends React.Component {
  constructor(props) {
    super(props);
    this.state = { count: 0 };
  }
  
  render() {
    return <h1>Count: {this.state.count}</h1>;
  }
}

// Functional Component
function Welcome() {
  const [count, setCount] = useState(0);
  return <h1>Count: {count}</h1>;
}
AspectClassFunctional
Modern approachLegacy (पहले का तरीका)Modern (अब preferred)

Was this answer clear?