Functional Components
In functional components, you need to export the default function export default function component() {} return to render content on the page and you can use React Hooks easily without worrying about this keyword
Example:-
export default function App () {
const [count , setCount ] = useState(0)
useEffect (()=> {
// start
} , [])
useEffect (()=> {
// update
} , [])
return (
<> jsx </>
)
}
Class Base Components
In class base components first, you have to inherit your class from
React.Component. Class Base Components use render function to render
content on the page. if you wana to use React Hooks its syntax is little bit
different than functional components and you also have to add the this
keyword with every variable
Example
class App extends React.Component {
constructor (props) {
super(props)
this.state = { count : 0 }
// this.setState( {count : this.state.count })
}
// useEffect Syntax
componentDidMount() {
// start
}
componentDidUpdate() {
// do update
}
componentWillUnmount(){
// on destory
}
render () {
return ( <> JSX </> )
}
}