01 Basics - biswajitsundara/react GitHub Wiki

React is a client side JavaScript library that helps to build modern reactive user interfaces for web.

  • React is an UI library created by Facebook
  • React follows component based architecture (UI components)
  • Basically we build custom HTML elements using React
  • React is declarative (say what to do without explicitly specifying each instruction)

Components

  • Components are independent and reusable block of code.
  • This is similar to Java script function however works in isolation and returns HTML.
  • A component is mainly consists of HTML + CSS + JS
  • The advantage of using component architecture is - Reusability & Separate Concerns

Component Tree

React & ReactDOM

  • React & react dom are two libraries that we are going to work
  • We write all the codes in javascript
  • index.js file is the first to execute

Imperative vs Declarative

  • In imperative approach we give each and every instruction to the DOM
  • Vanilla javascript is an imperative approach.
<html>
   <body id="root">
       <script>
            const para = document.createElement('p');
            para.textContent = 'This is visible';
            document.getElementById('root').append(para);
       </script>
    </body>
</html>
  • But in react, it will be declarative approach
  • We need to specify what do we want on the screen
  • And react will generate the instructions.
⚠️ **GitHub.com Fallback** ⚠️