what is component in react code example

Example 1: class app extends component syntax

class Welcome extends React.Component {
  render() {
    return 

Hello, {this.props.name}

; } }

Example 2: react component

/* React Component Template */
export default class MyComponent extends React.Component {
  constructor(props) {
    super(props);
	this.state = {
		//state properties here
	};
  }
  render() {
	return (
		
); } }

Example 3: what does componentDidCatch do in react

class ErrorBoundary extends React.Component {
  constructor(props) {
    super(props);
    this.state = { hasError: false };
  }

  static getDerivedStateFromError(error) {    // Update state so the next render will show the fallback UI.    return { hasError: true };  }
  componentDidCatch(error, errorInfo) {    // You can also log the error to an error reporting service    logErrorToMyService(error, errorInfo);  }
  render() {
    if (this.state.hasError) {      // You can render any custom fallback UI      return 

Something went wrong.

; } return this.props.children; } }

Example 4: React Components

class Car extends React.Component {
  render() {
    return 

Hi, I am a Car!

; } }

Example 5: react component example

const element = 
;

Tags:

Misc Example