Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
January 12, 2022 03:52 pm GMT

Core Concepts of React

JSX: In React JSX is the syntactic sugar of javascript. Where it looks like HTML syntax but actually its not the HTML. Under the hood, it used babel to convert HTML syntax into javascript.

Image description

State: In react, the state is used to keep the component updated after any changes are applied and update it. The state is managed by the component when anything changes on the component.

Image description

Here setCount updates the count and it is maintained by useState hook.

Props: Props are the value of the component which is not maintained by the component itself rather it shows in the component or is passed to another component.

Image description

Here, the count is the props that are used in the component using JSX.

Hooks: Hooks are the function that is used in react to maintain or make it easier to update the state or give different functionality to make an entire application easily with it. It is used in the functional components. useState, useEffect, useParams, useRef, useLocation, useHistory, useRouteMatch, useContext are some of the commonly used hooks. There are also custom hooks available that take hooks use case to the next level like logic and view shareable like props in custom hooks.

useState: useState update the state value if any change is applied. The updated state is then used for the component.

Image description

useEffect: If any types of side effects are applied frequently in this case useEffect is applied. Appling dependency on useEffect hook we can frequently update the specific state rather than updating the whole state.

Image description

useContext: useContext is used to make props passing highly easier. When props drilling become much complex the useContext makes props pass simple and organized way from the root. Where any component can use any exported props easily throw it.

Image description

useParams: Depending on route dynamic id matching it matches and goes to the route and shows the component.

Image description

useLocation: To work with query string parameters useLocation is generally used. It mainly gets pathname or state

Image description

useHistory: It is used to navigate the location from and pass to the new location using push. Other tasks are also applied depending on history action.

Image description

useRouteMatch: If any match the object find then access is provided by useRouteMatch. Depending on route match it provides the component.

useRef: It returns an object. Depending on the current value it updates the state.


Original Link: https://dev.to/tanvirfahimbd/core-concepts-of-react-33ng

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To