Components
Class Components
Functional Components
React functional components are like JavaScript functions.
Rendering a Component
What's happening here is :
We call
ReactDOM.render()
with the<Welcome name="World" />
element.React calls the
Welcome
component with{name: 'World'}
as the props.Our
Welcome
component returns a<h1>Hello, World</h1>
element as the result.React DOM efficiently updates the DOM to match
<h1>Hello, World</h1>
.
Component name should always start with Capital letter otherwise react treat them as DOM tags
Example:
<div>
represents HTML div tag
<Welcome>
represents a react component
Composing Components
Components can refer other components in their output.
Props are read only.
A function or class which never modify its own props are called "pure" because they don't change their input and produce same result every time with the same inputs.
All React components must act like pure functions with respect to their props.
props get passed to the component (similar to function parameters) whereas state is managed within the component (similar to variables declared within a function).
Last updated