React Mindset: How New React Developers Should Think
Amir H. Moayeri

Amir H. Moayeri @ymir

About: JavaScript opened up a whole new world of possibilities for me, and I quickly fell in love with both back-end and front-end development.

Location:
Tehran, Iran
Joined:
Dec 13, 2023

React Mindset: How New React Developers Should Think

Publish Date: Sep 16 '24
979 60

React, a popular JavaScript library for building user interfaces, has revolutionized front-end development by enabling developers to create reusable components and manage complex UIs efficiently. However, adopting the right mindset is crucial for new developers to navigate React's unique paradigms. Let’s explore the essential principles and strategies that shape the "React mindset."

1. Think in Components

One of the core concepts in React is component-based architecture. Instead of building entire pages or applications in a single file, React encourages breaking down the UI into smaller, reusable components. This modularity improves maintainability and scalability.

How to think in components:

  • Identify repetitive patterns in the UI and break them down into reusable pieces.

  • Each component should ideally handle one specific task (e.g., Button, Header, Card).

  • Components should be small and focused on one function or responsibility (often called the "single responsibility principle").

When approaching a UI, start by dividing it into a component tree. At the root is your main Appcomponent, which can house other components like Header, Footer, and MainContent.

2. Embrace Declarative Programming

React takes a declarative approach, meaning you define what the UI should look like based on the current application state, rather than imperatively describing how to manipulate the DOM step-by-step.

How to think declaratively:

  • Think of your components as descriptions of the UI, where the UI will react to changes in state.

  • Instead of manipulating the DOM directly, React handles updating the DOM based on changes in state or props (properties passed to components).

  • Focus on the data flow. Your job is to set up the logic that determines what should be rendered based on the state of the application.

Example:

const MyComponent = () => {
  const [isLoggedIn, setIsLoggedIn] = useState(false);

  return (
    <div>
      {isLoggedIn ? <h1>Welcome Back!</h1> : <h1>Please Log In</h1>}
    </div>
  );
};
Enter fullscreen mode Exit fullscreen mode

In this example, the component simply declares what the UI should look like based on the isLoggedIn state.

3. Understand the Role of State and Props

React's power comes from its ability to manage dynamic data via state and props.

  • State is used for data that a component owns and manages internally.

  • Props are used to pass data from a parent component to a child component.

How to manage state and props:

  • Identify which data belongs in a component’s local state (use useState or useReducer) and which data should be passed down via props.

  • Only lift state up to the closest common ancestor when multiple components need to share it. This prevents unnecessary duplication and helps keep your components clean.

Understanding when and where to use state is critical. Overusing state can lead to complexity, while underusing it may limit your app’s interactivity.

4. Composition Over Inheritance

React encourages composition rather than inheritance. Components can be composed together, meaning that smaller components are combined to form larger ones, making the UI modular and easier to maintain.

How to think in terms of composition:

  • Design components to be flexible and reusable by passing down props, which allow them to render differently depending on the data.
  • Avoid tightly coupling components; instead, build them to be independent and self-contained.

For instance, rather than building different components for different buttons (e.g., PrimaryButton, SecondaryButton), you can create a single Button component and pass different styles or behaviors via props.

const Button = ({ label, onClick, variant }) => {
  return (
    <button className={`button ${variant}`} onClick={onClick}>
      {label}
    </button>
  );
};
Enter fullscreen mode Exit fullscreen mode

5. Think About Data Flow (Unidirectional)

In React, data flows in one direction: from parent to child components. This is known as unidirectional data flow, and it simplifies how data is managed across the app.

How to manage data flow:

  • Identify the "source of truth" for each piece of data and ensure it flows down through props.

  • Avoid trying to sync data between components by force; instead, lift state up to the nearest common ancestor when necessary.

Understanding the flow of data helps keep your app predictable, as you always know where data is coming from and how it changes over time.

6. Get Comfortable with JSX

JSX (JavaScript XML) is a syntax extension that looks like HTML but is used within JavaScript to describe UI. It allows you to write HTML-like code directly within JavaScript, making it easy to create UI elements.

How to think in JSX:

  • Write HTML-like syntax inside your JavaScript code, while remembering that it's actually JavaScript underneath.
  • Leverage JavaScript expressions inside JSX by wrapping them in curly braces {}.
const Greeting = ({ name }) => {
  return <h1>Hello, {name}!</h1>;
};
Enter fullscreen mode Exit fullscreen mode

JSX makes it intuitive to build dynamic UIs because you can seamlessly integrate logic (like conditionals and loops) inside your markup.

7. Learn Hooks

Hooks, introduced in React 16.8, allow you to use state and other React features in functional components. The most commonly used hooks are useState and useEffect.

How to use hooks effectively:

  • useState allows you to add state to functional components, making them dynamic.

  • useEffect lets you manage side effects (e.g., fetching data or updating the DOM) in functional components.

For example, one of useEffect use cases is used to fetch data after the component mounts:

useEffect(() => {
  fetchUserData();
}, []); // Empty dependency array means this runs only once after the initial render.
Enter fullscreen mode Exit fullscreen mode

Hooks enable developers to write cleaner, more maintainable code by replacing complex class component logic with simpler functional patterns.

8. Test and Debug Early

React's component-based structure lends itself to easy testing and debugging, especially when you develop with the mindset of isolating each component. Use tools like Jest and React Testing Library to test individual components in isolation.

How to approach testing:

  • Write unit tests for individual components.
  • Test how components behave with different sets of props and state.
  • Use debugging tools like React DevTools to inspect your component tree and state changes.

Conclusion

Adopting the right mindset when developing in React is essential for success. By thinking in components, embracing declarative programming, understanding state and props, and focusing on composition, you'll be able to build scalable and maintainable applications. Stay curious, and continue to refine your React mindset as the ecosystem evolves!

Comments 60 total

  • Mark Schlacter
    Mark SchlacterSep 16, 2024

    Love how this article breaks down the essential mindset for new React developers. Thinking in components, embracing declarative programming, and understanding state and props are key to mastering React. A great guide for anyone starting out!

    • Amir H. Moayeri
      Amir H. MoayeriSep 16, 2024

      Welcome to the community and thanks for reading Dear Mark 👍

  • Lakshmanan Krishnan
    Lakshmanan KrishnanSep 17, 2024

    Good Read.

  • Denny Wright
    Denny WrightSep 17, 2024

    Great summary!

  • Bill Hannah
    Bill HannahSep 17, 2024

    Nice introduction, but puts an emphasis on prop drilling and local state, and doesn't mention context at all. In your example, you have the logged-in status as local state, which it would never be. That would be determined by a context provider in the app component so you don't need to pass this value as a prop to every component in the tree

    • Aaron Reese
      Aaron ReeseSep 18, 2024

      True, but it is an article for beginners. Context or State stores are a more advanced concept and getting your head around useEffect is hard enough for newbies.
      Maybe a couple of lines about separating Application state (dark theme, is logged in, side menu open etc) from Data state (list of items, form contents failed validation l, data submission pending) would help.

  • Jahid2121
    Jahid2121Sep 18, 2024

    I wish I had these advice when I started, short and right to the point, Thanks brother,

  • Abosi Godwin
    Abosi GodwinSep 18, 2024

    A straight to the point article.

    I recommend following this guideline to any new React developer.

  • Fred Lunjevich
    Fred LunjevichSep 18, 2024

    This is a great summation of the mindset needed to be a competent React Dev.

    What is becoming more important now, is the ability to know how to think in server and client components and composing UI this way.

    This is an added layer of complexity that brings with it the need for careful thought about how state is managed (e.g. using query params instead of local state) and the flow of data. I guess that's an entirely different article!

  • huzaifa uddin
    huzaifa uddinSep 18, 2024

    Love how this article breaks down the essential mindset for new React developers.I work in a react native app development company in uae and personally Thinking in components, embracing declarative programming, and understanding state and props are key to mastering React.

  • Kashif Ullah
    Kashif UllahSep 18, 2024

    appreciated

  • Ashutosh
    AshutoshSep 18, 2024

    Currently learning React, needed a brief explanation of what is going on, where to start from. This helped me a lot. Thanks

  • Muhammad Ahsan
    Muhammad AhsanSep 18, 2024

    A comprehensive overview
    I was looking for articles like this for a long time but I hardly found so detailed guide

  • Godwin 'Kachi
    Godwin 'KachiSep 18, 2024

    Moments ago, I read from this platform how complex React had made a simple workflow.

    And now, I read about approaches to take to get the best out of React.

    Isn't Life beautiful 😍?

    It's just feel like react is a two edged sword 🗡️ ah

    • Godwin 'Kachi
      Godwin 'KachiNov 17, 2024

      Thanks to all that reacted to this post.

      For the context, I'm starting to learn react and would appreciate if I can get an accountability partner here.

  • LAWAL ABDULRAFIU KEHINDE
    LAWAL ABDULRAFIU KEHINDESep 18, 2024

    Without a doubt, the mindset is a major determinant whether you’ll write a good React code or not. Thinking in components leads the pack just as you have mentioned. As much as possible break down repetitive features into independent component and employ props to customize for different scenarios.
    This is an amazing article.

  • J XVW
    J XVWSep 19, 2024

    I'm tired of using React JS if the application is too big when I run it and the compilation process takes a long time, besides the complexity of the code which makes my head spin, especially if I want to change the code, there are no more dependency problems which are often depreciated, I throw away React JS so I use C# .Net which is easier.

    • Abraham
      AbrahamSep 19, 2024

      Try React with Vite, the compilation is lightning fast

    • Monsur Oyedeji
      Monsur OyedejiSep 20, 2024

      Yeah, use Vite and enjoy life.

  • Damian Cyrus
    Damian CyrusSep 19, 2024

    8 → 1. 😄
    This is also an important mindset, as you already know what the result should be, so write it down and then develop it until the expected result is shown.

  • Samuel Oyerinde
    Samuel OyerindeSep 19, 2024

    Nice read

  • Blessing Emejulu
    Blessing EmejuluSep 19, 2024

    Perfect summary for React course that I took in one month

  • Alois Sečkár
    Alois SečkárSep 19, 2024

    New React devs should flee while they still can, embrace Vue.js and see that everything is equal or better with it.

  • KC
    KCSep 20, 2024

    How would you tackle coupling vs cohesion problem in React?
    Components can be break down but if we overuse, there might disrupt the cohesion level of the code

  • Monsur Oyedeji
    Monsur OyedejiSep 20, 2024

    This is a very concise and significant article. These are very essential in the journey of a React Developer. And, these aren't applicable to only new developers but existing ones, as well, who aren't following the conventional way.
    Thanks for the article.

  • Tomas Herrou
    Tomas HerrouSep 20, 2024

    Would be nice (but maybe a hassle at the same time) to talk a bit more about React Server Components, server actions and all the new-releases coming in React 19. The industry is going in the direction of involving the server and the sooner the better to address those different mental models.

  • Ellis
    EllisSep 21, 2024

    Very good article :)

    -- The points 1-5 are really good, and a React developer needs to: become aware of them. Many developers are not.

    -- Then 6-7 are just basics/fundamentals which are not optional, one cannot "not use" them for any real React programming. They kinda dilute this post, imho ;o)

  • Wilfred Erdo
    Wilfred ErdoSep 21, 2024

    Its a refresher to read this kind of article

  • Anmol Baranwal
    Anmol BaranwalSep 21, 2024

    I mostly use Nextjs for my projects because it's far easier to work there. Most of these ones could be for any framework imo.

  • Kudzai Murimi
    Kudzai MurimiSep 21, 2024

    Well documented article, keep sharing with the community

  • Rense Bakker
    Rense BakkerSep 22, 2024

    Modern React developers should drop the distinction between state and props. Every piece of data in your app is state. Props is just short for properties that we all know from basic javascript functions (React components are just javascript functions). Props are used to pass state down to child components. React developers should think about data flow in this regard, particularly which components should manage the data and how far it should flow down the tree. Btw uni-directional data flow is just theory of how react works when rendering. In practice there are several ways to pass state up the component tree, for example using React context.

  • SoonA Ryan
    SoonA RyanSep 23, 2024

    I've primarily been a BE developer and delving into FE with React 18 (only now). This has been the most clear and consise explanation I have come across.

    Many thanks.

  • Mohamed Amine Terbah
    Mohamed Amine TerbahSep 23, 2024

    Here is a Love react for your React post.

  • MKXinrare
    MKXinrareSep 23, 2024

    Thanks for the article. I especially enjoyed the flow of the content.

  • Mayank
    MayankSep 24, 2024

    insightful article!

  • Devendra Singh
    Devendra SinghSep 25, 2024

    Well written article. I really liked how to part. Terminologies are commonly known but approach is important.

  • Enoch Boison
    Enoch BoisonSep 25, 2024

    It all makes sense now that I have some experience, it took me almost a year to transition from vanilla javascript to react. Nice piece!

  • Tomasz Bernat
    Tomasz BernatSep 26, 2024

    I like how this article can be used as guidelines when learning react and help keep focus on important stuff. Thanks a lot for this one!

  • Samuel Benson
    Samuel BensonOct 2, 2024

    perfect thank you

  • Edward Colón
    Edward ColónOct 3, 2024

    nice article

  • Chandra Panta Chhetri
    Chandra Panta ChhetriOct 4, 2024

    Nice overview of the most important concepts beginners should know!

  • Henrique Emanoel Viana
    Henrique Emanoel VianaOct 7, 2024

    Hello.
    Check out this Full-Stack React framework for Deno. It's really cool:
    faster_react

  • Kelvin Macharia
    Kelvin MachariaOct 11, 2024

    A very good piece. Just getting the hang of React, this resource goes a long way to help me understand basic React principle

  • Isa Ahamed San
    Isa Ahamed SanOct 12, 2024

    Though Many beginner wont understand these concept but 1.Think in Components can be understand by every beginner. I want to mention about 1 little thing about this section. Think SVG as a component too if you are using RAW SVG file. Pretty sure most of the beginner wont even think of it.

  • Obinna
    ObinnaOct 12, 2024

    Awesome article🚀.
    How would you advice a developer on the topic of testing. Whether it's end-to-end testing or writing unit tests

  • Julius “THIS_JULIUS” Razanauskas
    Julius “THIS_JULIUS” RazanauskasOct 15, 2024

    Big fan of testing when components are following the SRP, just better code overall :)

  • abuhanzala
    abuhanzalaOct 22, 2024

    Great breakdown of the React mindset! Thinking in components and declarative programming were game changers for me too. I sometimes struggle with state management in deeply nested components—have you used Context API or Redux in larger apps? I'd love to hear your thoughts on keeping things simple while scaling.

  • Abdul Ahad
    Abdul AhadOct 23, 2024

    Wow! great material now I can reference this to my junior students.

  • Egbaunu precious
    Egbaunu preciousOct 25, 2024

    I love this article!

  • Ashwin V
    Ashwin VOct 26, 2024

    Thank you

  • 77pintu
    77pintuOct 28, 2024

    Thanks for the great post!!!

  • Rahul Chauhan
    Rahul ChauhanNov 1, 2024

    great

  • styylz
    styylzNov 1, 2024

    Composition Over Inheritance
    Can you please explain more clearly, where is inheritance used in function components as you're using function approach to explain declarative approach

  • Timothy Omafe
    Timothy OmafeNov 13, 2024

    This is really amazing

  • Thiago Polati
    Thiago PolatiNov 16, 2024

    Thank you for this great article.

  • Amine
    AmineNov 22, 2024

    Good article, it summarizes the essential mindset of a React developer in concise steps.

    Maybe the note about lifting state up might be a bit confusing for newcomers? I'd suggest adding a diagram there to the principle, or explaining briefly what does "lifting state up" mean in one or two lines.

  • Captain Corgi
    Captain CorgiDec 19, 2024

    Nice topic!
    Getting familiar with the ReactJS now

  • Usaid Yousuf
    Usaid YousufJan 23, 2025

    The sneakiest way to publish an AI generated post. Still a great article btw

Add comment