Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 2944

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 61k
Author
Asked: November 26, 20242024-11-26T10:08:07+00:00 2024-11-26T10:08:07+00:00

All of Reacts concepts- one article

  • 61k

React, developed by Facebook, has transformed web development with its component-based architecture and efficient rendering. However, mastering React requires a solid grasp of its core concepts.

In this comprehensive article, we'll explore all the essential aspects of React. Whether you're a beginner or an experienced developer, this guide covers everything from components and state management to hooks and lifecycle methods.

By the end, you'll have a thorough understanding of React's ecosystem and be ready to build sophisticated, maintainable applications.

Components

A function that returns markup (JSX). Kind of like legos, basic building blocks of a react app.

function Profile() {   return (     <img       src="https://i.imgur.com/MK3eW3As.jpg"       alt="Katherine Johnson"     />   ); }  export default function Gallery() {   return (     <section>       <h1>Amazing scientists</h1>       <Profile />       <Profile />       <Profile />     </section>   ); }  
Enter fullscreen mode Exit fullscreen mode

Curly braces

Allows react to be dynamic by allowing values to pass through it.

 <img       className="avatar"       src={avatar}       alt={description}     /> 
Enter fullscreen mode Exit fullscreen mode

Fragments

An empty component is usually used as a parent container to return multiple components simultaneously.

<>      <ChildComponent /> </> 
Enter fullscreen mode Exit fullscreen mode

Props

The parameters passed through containers. Anything can be a prop including other components (as children, known as composition).

A 'key' in props (similar to the primary key in SQL) is used to identify a component. Usually, it is the current index.

// Writing a function that supports props function Avatar({ person, size }) {   return (     <img       className="avatar"       src={getImageUrl(person)}       alt={person.name}       width={size}       height={size}     />   ); }  // Using props with the component return (     <Avatar       person={{ name: 'Lin Lanying', imageId: '1bX5QH6' }}       size={100}     />   ); 
Enter fullscreen mode Exit fullscreen mode

Rendering

Works by using a virtual DOM (VDOM). how does it work:

  • State changed? update VDOM to reflect changes
  • 'Diff'ing is performed: Check for changes between DOM and VDOM.
  • 'Reconciliation' with the DOM is performed.

Image courtesy of Telerik.com, Describes rendering in react

Event Handling

Handles different events like onClick(), onChange(), and onSubmit().

Image description

State

A snapshot of the app at any given point. We use special functions like useState and useReducer.

function Example() {   // Declare a new state variable, which we'll call "count"   const [count, setCount] = useState(0);    return (     <div>       <p>You clicked {count} times</p>       <button onClick={() => setCount(count + 1)}>         Click me       </button>     </div>   ); } 
Enter fullscreen mode Exit fullscreen mode

Controlled Components

Components used by a state to have a more predictable behaviour.

const [value, setValue] = useState('') 
Enter fullscreen mode Exit fullscreen mode

We change the state to change the behaviour.

Hooks

It allows us to hook into features like state within function components. There are 5 types of hooks:

  • State Hooks- useState, useReducer, to manage state
  • Context Hooks- useContext, use data through context
  • Ref Hooks- useRef, to reference HTML
  • Effect Hooks- useEffect, Lets you connect to external systems and APIs.
  • Performance Hooks- useMemo, useCallback, Boosts performance.

Types of hooks in react

Purity

Describes how react components should work (Like the one in Functional Programming). It follows two rules:

  • Only return JSX
  • Don't change stuff that existed before rendering

Strict Mode

A component that detects problems during app development. Here's how to use it:

<StrictMode>   <App /> </StrictMode> 
Enter fullscreen mode Exit fullscreen mode

Effects

Code that reaches outside the react application (like an API). Best done using event handlers or useEffect.

function ChatRoom({ roomId }) {   const [serverUrl, setServerUrl] = useState('https://localhost:1234');    useEffect(() => {     const connection = createConnection(serverUrl, roomId);     connection.connect();     return () => {       connection.disconnect();     };   }, [serverUrl, roomId]);   // ... } 
Enter fullscreen mode Exit fullscreen mode

Refs

Used to reference an element on DOM. Useful for tasks like focusing on an element.

export default function Counter() {   let ref = useRef(0);    function handleClick() {     ref.current = ref.current + 1;     alert('You clicked ' + ref.current + ' times!');   }    return (     <button onClick={handleClick}>       Click me!     </button>   ); } 
Enter fullscreen mode Exit fullscreen mode

Context

Passing data without sending as props.

function Button() {   const theme = useContext(ThemeContext);   return <button className={theme} />; } 
Enter fullscreen mode Exit fullscreen mode

Image courtesy of Shamalka Vanod (medium)

Portals

Context for components. Ideal for modals, dropdowns and tooltips.

<div>   <p>This child is placed in the parent div.</p>   {createPortal(     <p>This child is placed in the document body.</p>,     document.body   )} </div> 
Enter fullscreen mode Exit fullscreen mode

Suspense

Component to wait for something to load/occur. Provides a fallback UX till the other component is fetched/rendered.

<Suspense fallback={<Loading />}>   <SomeComponent /> </Suspense> 
Enter fullscreen mode Exit fullscreen mode

Error Boundaries

Component to show a fallback component should that app encounter an error (like a 404 page).

export function MessageContainer({ messagePromise }) {   return (     <ErrorBoundary fallback={<p>⚠️Something went wrong</p>}>       <Suspense fallback={<p>⌛Downloading message...</p>}>         <Message messagePromise={messagePromise} />       </Suspense>     </ErrorBoundary>   ); }  function Message({ messagePromise }) {   const content = use(messagePromise);   return <p>Here is the message: {content}</p>; }  
Enter fullscreen mode Exit fullscreen mode

References:
React Dev

beginnersreacttutorialwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 2k
  • Popular
  • Answers
  • Author

    ES6 - A beginners guide - Template Literals

    • 0 Answers
  • Author

    Understanding Higher Order Functions in JavaScript.

    • 0 Answers
  • Author

    Build a custom video chat app with Daily and Vue.js

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.