Introduction to React and Components
Component Based Architecture
Component
React components are independent and reusable code. They are the building blocks of any React application. Components serve the same purpose as JavaScript functions, but work individually to return JSX code as elements for our UI. Components usually come in the following types:
- Functional Components: In simple words, Functional components are javascript functions.
- Class Components.
- Higher-Order Components.
- Dumb Components.
- Smart Components.
- Presentational Components.
- Container components.
The charactistics of a component
-
Reusability − Components are usually designed to be reused in different situations in different applications. However, some components may be designed for a specific task.
-
Replaceable − Components may be freely substituted with other similar components.
-
Not context specific − Components are designed to operate in different environments and contexts.
-
Extensible − A component can be extended from existing components to provide new behavior.
-
Encapsulated − A component depicts the interfaces, which allow the caller to use its functionality, and do not expose details of the internal processes or any internal variables or state.
-
Independent − Components are designed to have minimal dependencies on other components.
The advantages of using component based architecture
-
Ease of deployment.
-
Reduced cost.
-
Ease of development.
-
Reusable.
-
Modification of technical complexity.
-
Reliability.
-
System maintenance and evolution.
-
Independent.
What is Props and How to Use it in React
What is props short for?
Propsstands for properties. It is a special keyword in React which is used for passing data from one component to another. Logically, components are just like JavaScript functions. They accept random inputs (called “props”) and return React elements which tell what should be displayed on the screen.
Props can be used to pass any kind of data such as:
- String
- Array
- Integer
- Boolean
- Objects or,Functions
How are props used in React
- Firstly, define an attribute and its value(data)
- Then pass it to child component(s) by using Props
- Finally, render the Props Data
The flow of props
Props have a one way downward binding between the parent and child component. When the parent property updates, then the updates are passed into the child via props. This prevents child components from accidentally mutating the parent’s state.
Things I want to know more about
- connecting the components with each other to build interface.
- how to use the props inside a react app.