A single-page application (SPA) is a web application or website that loads a single HTML page and dynamically updates the page as the user interacts with the application. SPAs are different from traditional web applications, which load a new HTML page every time the user clicks a link. This means that SPAs can provide a more responsive and fluid user experience, as well as faster loading times.
There are two types of components:
Before making class based component we need to inherit functions from React.Component
and this can be done with extends
, like this:
class Cat extends React.Component {
render() {
return <h1>Meow</h1>;
}
}
it also requires a render
method which returns HTML.
In function it's simpler, we just need to return the HTML, like this:
function Cat() {
return <h1>Meow</h1>;
}
Note: Component's name must start with uppercase letter.
React.Component
.this.state
to manage state and this.setState
to update it.useState
hook for state management.componentDidMount
, componentDidUpdate
, and componentWillUnmount
.useEffect
hook to handle side effects and lifecycle events.