What are Components in ReactJS ?

devquora
devquora

Posted On: May 29, 2024

 

React Components let you split the UI into independent, reusable pieces, and think about each piece in isolation.

Conceptually, components are like JavaScript functions. They accept arbitrary inputs (called “props”) and return React elements describing what should appear on the screen.

Below is ample component written in ES6 class to display a welcome message on the screen.

class Welcome extends React.Component {
  render() {
    return <h1>Hello, {this.props.name} </h1>;
  }
}

const element = <Welcome name="Sara" />;
ReactDOM.render(
  element,
  document.getElementById('root')
);

source: https://facebook.github.io/react/docs/components-and-props.html

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    React Js Interview Questions

    What is ReactJS ?

    ReactJS, created by Facebook, is a JavaScript library for crafting dynamic, stateful, and reusable user interface components. It's renowned for simplifying the presentation layer of web and mobile app..

    React Js Interview Questions

    List some advantages of ReactJS ?

    React.js offers efficiency with its virtual DOM, simplifies JavaScript with JSX, provides developer tools, enhances SEO, and facilitates UI test cases effortlessly...

    React Js Interview Questions

    What is JSX in React Js?

    JSX, integral to React, merges HTML-like syntax with JavaScript, streamlining UI development. Preprocessors such as Babel transform JSX into standard JavaScript objects for parsing by JavaScript engin..