<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Elias Garcia</title>
    <description>The latest articles on DEV Community by Elias Garcia (@deep_raval_16fa6674dda823).</description>
    <link>https://dev.to/deep_raval_16fa6674dda823</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2556061%2F9804e8dd-6115-4abb-b90e-d5204350b135.png</url>
      <title>DEV Community: Elias Garcia</title>
      <link>https://dev.to/deep_raval_16fa6674dda823</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/deep_raval_16fa6674dda823"/>
    <language>en</language>
    <item>
      <title>Managing State Effectively in Your React Single-Page Application</title>
      <dc:creator>Elias Garcia</dc:creator>
      <pubDate>Mon, 14 Jul 2025 06:23:52 +0000</pubDate>
      <link>https://dev.to/deep_raval_16fa6674dda823/managing-state-effectively-in-your-react-single-page-application-23i8</link>
      <guid>https://dev.to/deep_raval_16fa6674dda823/managing-state-effectively-in-your-react-single-page-application-23i8</guid>
      <description>&lt;p&gt;You have already understood &lt;a href="https://dev.to/getsmartwebsite/building-your-first-single-page-application-with-reactjs-a-beginners-guide-nbf"&gt;how to develop a single-page application (SPA) with React.js&lt;/a&gt;. I am sure your app must be looking good and navigating smoothly. However, there is one issue that you may face or may be facing: managing state effectively. &lt;/p&gt;

&lt;p&gt;State management can be the most challenging part of scaling a React single-page application. I have written this article to explain why state management can be complex, and I have also written some practical strategies to resolve the issues of managing state.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmzy52l8sd668yb0dw1lq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmzy52l8sd668yb0dw1lq.png" alt="State Management in React SPA" width="800" height="252"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you find the strategies and examples of state management helpful to keep your SPA easy to maintain, fast, and scalable, please leave a comment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why State Management Is a Challenge in React SPAs
&lt;/h2&gt;

&lt;p&gt;In the React single-page application, state determines how your application behaves and what users see. Along with the growth of your app, the complexity of managing state across components also rises. These are a few of the common pain points around state management: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Prop Drilling:&lt;/strong&gt; The code gets messy and complicated to maintain when we pass the state through several layers of components. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Complex State Logic:&lt;/strong&gt; It becomes difficult to manage state updates between components, mainly when those components rely on each other or when they involve asynchronous tasks such as API calls. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Performance Issues:&lt;/strong&gt; State changes trigger unnecessary re-renders that often slow down the SPA. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalability:&lt;/strong&gt; Local state with &lt;code&gt;useState&lt;/code&gt; works well with a small app, but often fails to scale for larger apps that have shared or global state needs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftzhhucpd3u5l8h16va7h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftzhhucpd3u5l8h16va7h.png" alt="State Mangement in single page application" width="800" height="465"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But there is nothing to worry about, React provides built-in-tools, and the ecosystem offers powerful libraries to address these issues.&lt;/p&gt;

&lt;p&gt;Let’s get started with the structured approach to effective state management. &lt;/p&gt;

&lt;h2&gt;
  
  
  Strategies for Effective State Management
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Leverage React’s Built-in Hooks for Simplicity
&lt;/h3&gt;

&lt;p&gt;If your SPAs are small or medium-sized, React’s built-in hooks like &lt;code&gt;useState&lt;/code&gt; and &lt;code&gt;useReducer&lt;/code&gt; would be sufficient. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;useState&lt;/code&gt;:&lt;/strong&gt; Ideal for simple, component-level state like form inputs or toggles.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from 'react';

function Counter() {
  const [count, setCount] = useState(0);
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;p&amp;gt;Count: {count}&amp;lt;/p&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; setCount(count + 1)}&amp;gt;Increment&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;code&gt;useReducer&lt;/code&gt;:&lt;/strong&gt; Better for complex state logic within a component, such as managing a form with multiple fields or a multi-step wizard.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useReducer } from 'react';

const initialState = { count: 0 };
function reducer(state, action) {
  switch (action.type) {
    case 'increment':
      return { count: state.count + 1 };
    case 'decrement':
      return { count: state.count - 1 };
    default:
      return state;
  }
}

function Counter() {
  const [state, dispatch] = useReducer(reducer, initialState);
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;p&amp;gt;Count: {state.count}&amp;lt;/p&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; dispatch({ type: 'increment' })}&amp;gt;Increment&amp;lt;/button&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; dispatch({ type: 'decrement' })}&amp;gt;Decrement&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Best Practice:&lt;/strong&gt; Keep the state as local as possible. Only lift state to parent components or global stores when multiple components need access. &lt;/p&gt;

&lt;h3&gt;
  
  
  2. Use Context API to Avoid Prop Drilling
&lt;/h3&gt;

&lt;p&gt;React’s Context API eliminates the need for prop drilling when multiple components need access to the same state, such as user authentication or theme settings.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { createContext, useContext, useState } from 'react';

const ThemeContext = createContext();

function App() {
  const [theme, setTheme] = useState('light');
  return (
    &amp;lt;ThemeContext.Provider value={{ theme, setTheme }}&amp;gt;
      &amp;lt;Toolbar /&amp;gt;
    &amp;lt;/ThemeContext.Provider&amp;gt;
  );
}

function Toolbar() {
  const { theme, setTheme } = useContext(ThemeContext);
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;p&amp;gt;Current Theme: {theme}&amp;lt;/p&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; setTheme(theme === 'light' ? 'dark' : 'light')}&amp;gt;
        Toggle Theme
      &amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Best Practice:&lt;/strong&gt; Combine Context with &lt;code&gt;useReducer&lt;/code&gt; for complex state updates to ensure predictable state transitions. Make sure, you are not overusing Context for all state, as it often leads to unnecessary re-renders.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Adopt State Management Libraries for Large Apps
&lt;/h3&gt;

&lt;p&gt;External libraries like Redux, Zustand, or Jotai provide robust solutions for complex singe-page applications with global state or intricate data flows. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Redux (with Redux Toolkit):&lt;/strong&gt; Offers a centralized store and predictable state updates, ideal for large teams and apps requiring strict structure.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { createSlice, configureStore } from '@reduxjs/toolkit';
import { Provider, useDispatch, useSelector } from 'react-redux';

const counterSlice = createSlice({
  name: 'counter',
  initialState: { value: 0 },
  reducers: {
    increment: (state) =&amp;gt; { state.value += 1; },
    decrement: (state) =&amp;gt; { state.value -= 1; },
  },
});

const store = configureStore({ reducer: counterSlice.reducer });
const { increment, decrement } = counterSlice.actions;

function Counter() {
  const count = useSelector((state) =&amp;gt; state.value);
  const dispatch = useDispatch();
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;p&amp;gt;Count: {count}&amp;lt;/p&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; dispatch(increment())}&amp;gt;Increment&amp;lt;/button&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; dispatch(decrement())}&amp;gt;Decrement&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

function App() {
  return (
    &amp;lt;Provider store={store}&amp;gt;
      &amp;lt;Counter /&amp;gt;
    &amp;lt;/Provider&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Zustand:&lt;/strong&gt; Lightweight and flexible, perfect for simpler global state needs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import create from 'zustand';

const useStore = create((set) =&amp;gt; ({
  count: 0,
  increment: () =&amp;gt; set((state) =&amp;gt; ({ count: state.count + 1 })),
  decrement: () =&amp;gt; set((state) =&amp;gt; ({ count: state.count - 1 })),
}));

function Counter() {
  const { count, increment, decrement } = useStore();
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;p&amp;gt;Count: {count}&amp;lt;/p&amp;gt;
      &amp;lt;button onClick={increment}&amp;gt;Increment&amp;lt;/button&amp;gt;
      &amp;lt;button onClick={decrement}&amp;gt;Decrement&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Jotai:&lt;/strong&gt; Atomic state management for fine-grained updates, integrating seamlessly with React’s component model.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { atom, useAtom } from 'jotai';

const countAtom = atom(0);

function Counter() {
  const [count, setCount] = useAtom(countAtom);
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;p&amp;gt;Count: {count}&amp;lt;/p&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; setCount(count + 1)}&amp;gt;Increment&amp;lt;/button&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; setCount(count - 1)}&amp;gt;Decrement&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Best Practice:&lt;/strong&gt; Choose based on your app’s needs: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Redux for strict structure and debugging (use Redux Toolkit to reduce boilerplate).&lt;/li&gt;
&lt;li&gt;Zustand for simplicity and minimal setup.&lt;/li&gt;
&lt;li&gt;Jotai for fine-grained control and scalability.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. Optimize Performance with Memoization
&lt;/h3&gt;

&lt;p&gt;State changes can trigger unnecessary re-renders, slowing down your SPA. Use React’s memoization tools to optimize performance:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;React.memo&lt;/code&gt;: Prevents re-rendering of components when props haven’t changed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const MemoizedComponent = React.memo(({ data }) =&amp;gt; &amp;lt;div&amp;gt;{data}&amp;lt;/div&amp;gt;);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;useMemo&lt;/code&gt;: Memoizes expensive computations.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const expensiveValue = useMemo(() =&amp;gt; computeExpensiveValue(data), [data]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;useCallback&lt;/code&gt;: Memoizes functions to prevent re-creation on every render.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const handleClick = useCallback(() =&amp;gt; doSomething(), []);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Best Practice:&lt;/strong&gt; Apply memoization only when performance issues arise, as premature optimization can add complexity.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Handle Asynchronous State with Data Fetching Libraries
&lt;/h3&gt;

&lt;p&gt;SPAs often rely on API data, requiring state synchronization. Libraries like React Query or SWR simplify async state management.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useQuery } from '@tanstack/react-query';

function UserProfile() {
  const { data, isLoading, error } = useQuery({
    queryKey: ['user'],
    queryFn: async () =&amp;gt; {
      const res = await fetch('https://api.example.com/user');
      return res.json();
    },
  });

  if (isLoading) return &amp;lt;div&amp;gt;Loading...&amp;lt;/div&amp;gt;;
  if (error) return &amp;lt;div&amp;gt;Error: {error.message}&amp;lt;/div&amp;gt;;
  return &amp;lt;div&amp;gt;Welcome, {data.name}!&amp;lt;/div&amp;gt;;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  6. Structure State Logically
&lt;/h3&gt;

&lt;p&gt;Group Related State: Store related data (e.g., form fields) in a single object or reducer to simplify updates. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Normalize Data:&lt;/strong&gt; For lists or nested data, normalize state to avoid deeply nested structures. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Separate UI and Data State:&lt;/strong&gt; Keep UI state (e.g., &lt;code&gt;isModalOpen&lt;/code&gt;) local and data state (e.g., API results) global. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt; (Normalized State with &lt;code&gt;useReducer&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const initialState = {
  users: {},
  userIds: [],
};

function reducer(state, action) {
  switch (action.type) {
    case 'addUser':
      return {
        users: { ...state.users, [action.payload.id]: action.payload },
        userIds: [...state.userIds, action.payload.id],
      };
    default:
      return state;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Best Practice:&lt;/strong&gt; Plan state structure upfront to avoid refactoring. Use TypeScript for type safety.&lt;/p&gt;

&lt;h3&gt;
  
  
  7. Encapsulate Logic in Custom Hooks
&lt;/h3&gt;

&lt;p&gt;Custom hooks make stateful logic reusable and testable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from 'react';

function useCounter(initialValue = 0) {
  const [count, setCount] = useState(initialValue);
  const increment = () =&amp;gt; setCount(count + 1);
  const decrement = () =&amp;gt; setCount(count - 1);
  return { count, increment, decrement };
}

function Counter() {
  const { count, increment, decrement } = useCounter();
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;p&amp;gt;Count: {count}&amp;lt;/p&amp;gt;
      &amp;lt;button onClick={increment}&amp;gt;Increment&amp;lt;/button&amp;gt;
      &amp;lt;button onClick={decrement}&amp;gt;Decrement&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Best Practice: Name hooks clearly (e.g., &lt;code&gt;useCounter&lt;/code&gt;) and keep them focused on a single concern.&lt;/p&gt;

&lt;h3&gt;
  
  
  8. Plan for Scalability
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Small Apps:&lt;/strong&gt; Start with &lt;code&gt;useState&lt;/code&gt; or &lt;code&gt;useReducer&lt;/code&gt; for local state.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Medium Apps:&lt;/strong&gt; Use Context for shared state, combined with &lt;code&gt;useReducer&lt;/code&gt; or custom hooks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Large Apps:&lt;/strong&gt; Adopt Redux, Zustand, or Jotai, and use React Query for async data.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Best Practice:&lt;/strong&gt; Refactor to a more robust solution only when complexity justifies it. Avoid over-engineering early.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example: Putting It All Together
&lt;/h2&gt;

&lt;p&gt;Here’s a sample SPA structure combining these strategies:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Local State:&lt;/strong&gt; Use &lt;code&gt;useState&lt;/code&gt; for a form component.&lt;br&gt;
&lt;strong&gt;Shared State:&lt;/strong&gt; Use Context for theme settings.&lt;br&gt;
&lt;strong&gt;Async Data:&lt;/strong&gt; Use React Query for fetching user data.&lt;br&gt;
&lt;strong&gt;Custom Hooks:&lt;/strong&gt; Encapsulate form logic.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { createContext, useContext, useState } from 'react';
import { useQuery } from '@tanstack/react-query';

const ThemeContext = createContext();

function useForm() {
  const [input, setInput] = useState('');
  const handleChange = (e) =&amp;gt; setInput(e.target.value);
  return { input, handleChange };
}

function App() {
  const [theme, setTheme] = useState('light');
  return (
    &amp;lt;ThemeContext.Provider value={{ theme, setTheme }}&amp;gt;
      &amp;lt;div className={theme === 'light' ? 'bg-white' : 'bg-gray-800'}&amp;gt;
        &amp;lt;UserProfile /&amp;gt;
        &amp;lt;Form /&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/ThemeContext.Provider&amp;gt;
  );
}

function UserProfile() {
  const { data, isLoading } = useQuery({
    queryKey: ['user'],
    queryFn: async () =&amp;gt; {
      const res = await fetch('https://api.example.com/user');
      return res.json();
    },
  });
  if (isLoading) return &amp;lt;div&amp;gt;Loading...&amp;lt;/div&amp;gt;;
  return &amp;lt;div&amp;gt;Welcome, {data.name}!&amp;lt;/div&amp;gt;;
}

function Form() {
  const { input, handleChange } = useForm();
  const { theme, setTheme } = useContext(ThemeContext);
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;input value={input} onChange={handleChange} className="border p-2" /&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; setTheme(theme === 'light' ? 'dark' : 'light')}&amp;gt;
        Toggle Theme
      &amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;p&gt;State management doesn’t have to be a roadblock in your React SPA. By understanding your app’s needs and leveraging the right tools, you can create a maintainable, performant, and scalable application. If you need to outsource this project to avoid such complexity, always connect with a reliable &lt;a href="https://www.lucentinnovation.com/services/reactjs-development" rel="noopener noreferrer"&gt;React.js development company&lt;/a&gt; with a good record. &lt;/p&gt;

&lt;p&gt;Plan your state structure early, keep components focused, and optimize only when necessary. With these strategies, you’ll turn state management from a challenge into a strength, ensuring your SPA delivers a seamless user experience. &lt;/p&gt;

&lt;p&gt;Keep a note of the following takeaways: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Start Simple:&lt;/strong&gt; Use &lt;code&gt;useState&lt;/code&gt; or &lt;code&gt;useReducer&lt;/code&gt; for small apps, and scale to Context or libraries as needed. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Optimize Wisely:&lt;/strong&gt; Apply memoization (&lt;code&gt;React.memo&lt;/code&gt;, &lt;code&gt;useMemo&lt;/code&gt;, &lt;code&gt;useCallback&lt;/code&gt;) only when performance issues arise. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Handle Async Gracefully:&lt;/strong&gt; Use React Query or SWR for API-driven state. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Structure Thoughtfully:&lt;/strong&gt; Normalize data, separate UI and data state, and use custom hooks for reusability. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Debug Efficiently:&lt;/strong&gt; Use React DevTools or Redux DevTools to inspect state changes. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Type Safety:&lt;/strong&gt; Consider TypeScript to catch state-related errors early. &lt;/p&gt;

</description>
      <category>react</category>
      <category>statemanagement</category>
      <category>statemanagementspa</category>
      <category>reactsinglepageapplication</category>
    </item>
    <item>
      <title>Building Your First Custom Shopify Storefront with React.js: A Beginner’s Guide</title>
      <dc:creator>Elias Garcia</dc:creator>
      <pubDate>Wed, 18 Jun 2025 07:22:37 +0000</pubDate>
      <link>https://dev.to/deep_raval_16fa6674dda823/building-your-first-custom-shopify-storefront-with-reactjs-a-beginners-guide-4121</link>
      <guid>https://dev.to/deep_raval_16fa6674dda823/building-your-first-custom-shopify-storefront-with-reactjs-a-beginners-guide-4121</guid>
      <description>&lt;p&gt;If you’re new to web development or e-commerce, creating a custom Shopify storefront with React.js might sound daunting. But don’t worry! You've landed at the right place.&lt;br&gt;
My beginner-friendly guide will walk you through every step, from setting up your Shopify store to building a beautiful, functional storefront using React.js.&lt;br&gt;
By the end, you’ll have a working store displaying products and a basic cart, all explained in simple terms.&lt;/p&gt;
&lt;h2&gt;
  
  
  Why Build a Custom Shopify Storefront with React.js?
&lt;/h2&gt;

&lt;p&gt;Shopify is a powerful platform for creating online stores, but its default themes might not always match your vision. A custom storefront lets you design a unique shopping experience tailored to your brand.&lt;br&gt;
Using React.js, a popular JavaScript library, you can build fast, interactive, and reusable components for your store. Plus, Shopify’s Storefront API makes it easy to fetch product data and manage cart functionality.&lt;br&gt;
This guide is perfect for beginners because:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We’ll use simple tools and explain every step.&lt;/li&gt;
&lt;li&gt;You’ll learn practical React.js concepts like components and state management.&lt;/li&gt;
&lt;li&gt;You’ll see how to connect React.js with Shopify’s API.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before we start, make sure you have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A Shopify Account:&lt;/strong&gt; Sign up for a free trial at &lt;a href="https://www.shopify.com/" rel="noopener noreferrer"&gt;shopify.com&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Basic JavaScript Knowledge:&lt;/strong&gt; Familiarity with variables, functions, and arrays is enough.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Node.js Installed:&lt;/strong&gt; Download it from &lt;a href="https://nodejs.org/" rel="noopener noreferrer"&gt;nodejs.org&lt;/a&gt;. This lets you run JavaScript tools on your computer.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A Text Editor:&lt;/strong&gt; Use Visual Studio Code (free at &lt;a href="https://code.visualstudio.com/" rel="noopener noreferrer"&gt;code.visualstudio.com&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A Shopify Storefront API Token:&lt;/strong&gt; We’ll cover how to get this below.
No prior React.js or Shopify experience? No problem! I’ll explain everything.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Step-by-Step Guide
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Step 1: Set Up Your Shopify Store and Storefront API
&lt;/h3&gt;

&lt;p&gt;To build a custom storefront, you need a Shopify store and access to its Storefront API, which lets your React app fetch products, prices, and more.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Create a Shopify Store&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to shopify.com and sign up.&lt;/li&gt;
&lt;li&gt;Follow the prompts to set up a basic store. Add a few products (with names, prices, and images) for testing.&lt;/li&gt;
&lt;li&gt;Note your store’s domain, like &lt;code&gt;your-store.myshopify.com&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Enable the Storefront API&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Log in to your Shopify admin (e.g., &lt;code&gt;your-store.myshopify.com/admin&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Go to Apps &amp;gt; Develop apps &amp;gt; Create an app.&lt;/li&gt;
&lt;li&gt;Give your app a name, like “Custom Storefront.”&lt;/li&gt;
&lt;li&gt;Under API access, enable the Storefront API.&lt;/li&gt;
&lt;li&gt;Click Save, then copy the Storefront API access token. This is a secret key, so don’t share it publicly!&lt;/li&gt;
&lt;li&gt;The API endpoint for your store is &lt;code&gt;https://your-store.myshopify.com/api/2025-01/graphql.json&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Test the API (Optional)&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use a tool like &lt;a href="https://www.postman.com" rel="noopener noreferrer"&gt;Postman&lt;/a&gt; or &lt;a href="https://shopify.dev/docs/api/storefront" rel="noopener noreferrer"&gt;GraphiQL&lt;/a&gt; to test your API.&lt;/li&gt;
&lt;li&gt;Send a GraphQL query like:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight graphql"&gt;&lt;code&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;query&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="n"&gt;products&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;first&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
     &lt;/span&gt;&lt;span class="n"&gt;edges&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
         &lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
     &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Include your API token in the request headers (&lt;code&gt;X-Shopify-Storefront-Access-Token&lt;/code&gt;). If you see product titles, your API is ready!&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Step 2: Set Up Your React Project
&lt;/h3&gt;

&lt;p&gt;React.js lets you build your storefront as reusable components, like product cards or a cart. We’ll use Vite, a fast tool for creating React projects.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Install Vite and Create a Project&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open your terminal (Command Prompt on Windows, Terminal on Mac/Linux).&lt;/li&gt;
&lt;li&gt;Run these commands:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; npm create vite@latest shopify-storefront &lt;span class="nt"&gt;--template&lt;/span&gt; react
 &lt;span class="nb"&gt;cd &lt;/span&gt;shopify-storefront
 npm &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;This creates a folder called &lt;code&gt;shopify-storefront&lt;/code&gt; with a basic React app.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Install Additional Tools&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We’ll use &lt;strong&gt;Apollo Client&lt;/strong&gt; to connect to Shopify’s GraphQL API and &lt;strong&gt;Tailwind CSS&lt;/strong&gt; for easy styling.&lt;/li&gt;
&lt;li&gt;Run:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; npm &lt;span class="nb"&gt;install&lt;/span&gt; @apollo/client graphql tailwindcss postcss autoprefixer
 npx tailwindcss init &lt;span class="nt"&gt;-p&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;This installs Apollo Client (for API calls) and sets up Tailwind CSS.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Configure Tailwind CSS&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open &lt;code&gt;tailwind.config.js&lt;/code&gt; in your project folder and replace its contents with:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="cm"&gt;/** @type {import('tailwindcss').Config} */&lt;/span&gt;
 &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./index.html&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./src/**/*.{js,ts,jsx,tsx}&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
   &lt;span class="na"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;extend&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
   &lt;span class="na"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;
 &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Open &lt;code&gt;src/index.css&lt;/code&gt; and add:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight css"&gt;&lt;code&gt; &lt;span class="k"&gt;@tailwind&lt;/span&gt; &lt;span class="n"&gt;base&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="k"&gt;@tailwind&lt;/span&gt; &lt;span class="n"&gt;components&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="k"&gt;@tailwind&lt;/span&gt; &lt;span class="n"&gt;utilities&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;&lt;p&gt;These settings make Tailwind CSS work with your React app.&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Start the Development Server&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Run:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Open your browser to &lt;code&gt;http://localhost:5173&lt;/code&gt; (or the URL shown in the terminal). You’ll see a default Vite + React page.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 3: Connect to Shopify’s Storefront API
&lt;/h3&gt;

&lt;p&gt;Now, let’s connect your &lt;a href="https://dev.to/deep_raval_16fa6674dda823/building-scalable-react-apps-best-practices-for-performance-and-maintainability-5cmc"&gt;scalable React app&lt;/a&gt; to Shopify’s API using Apollo Client. This lets you fetch products and display them.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Set Up Apollo Client&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a file to initialize Apollo Client, which handles API requests.&lt;/li&gt;
&lt;li&gt;Open &lt;code&gt;src/main.jsx&lt;/code&gt; and replace its contents with:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createRoot&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-dom/client&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ApolloClient&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;InMemoryCache&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ApolloProvider&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;HttpLink&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@apollo/client&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./App&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

 &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ApolloClient&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
   &lt;span class="na"&gt;link&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;HttpLink&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
     &lt;span class="na"&gt;uri&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://your-store.myshopify.com/api/2025-01/graphql.json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
     &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;X-Shopify-Storefront-Access-Token&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;your-storefront-api-token&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
     &lt;span class="p"&gt;},&lt;/span&gt;
   &lt;span class="p"&gt;}),&lt;/span&gt;
   &lt;span class="na"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;InMemoryCache&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
 &lt;span class="p"&gt;});&lt;/span&gt;

 &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;root&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createRoot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
 &lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
   &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ApolloProvider&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
     &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
   &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/ApolloProvider&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Replace &lt;code&gt;your-store.myshopify.com&lt;/code&gt; with your store’s domain and &lt;code&gt;your-storefront-api-token&lt;/code&gt; with your API token from Step 1.&lt;/li&gt;
&lt;li&gt;This code:

&lt;ul&gt;
&lt;li&gt;Creates an Apollo Client instance to talk to Shopify’s API.&lt;/li&gt;
&lt;li&gt;Wraps your app in &lt;code&gt;ApolloProvider&lt;/code&gt;, so all components can use the API.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Test the Connection&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;For now, your app should still show the default page. We’ll update it to fetch products next.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Step 4: Build the Storefront Components
&lt;/h3&gt;

&lt;p&gt;Let’s create components to display products and a cart. We’ll break this into:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A main ` component to fetch and manage data.&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;ProductList&lt;/code&gt; component to show product cards.&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;Cart&lt;/code&gt; component to show items added by the user.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Update the Main App Component&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Replace &lt;code&gt;src/App.jsx&lt;/code&gt; with:&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
import React, { useState } from 'react';&lt;br&gt;
     import { useQuery, gql } from '&lt;a class="mentioned-user" href="https://dev.to/apollo"&gt;@apollo&lt;/a&gt;/client';&lt;br&gt;
     import ProductList from './components/ProductList';&lt;br&gt;
     import Cart from './components/Cart';&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; const GET_PRODUCTS = gql`
   query {
     products(first: 10) {
       edges {
         node {
           id
           title
           handle
           description
           images(first: 1) {
             edges {
               node {
                 src
               }
             }
           }
           variants(first: 1) {
             edges {
               node {
                 id
                 priceV2 {
                   amount
                   currencyCode
                 }
               }
             }
           }
         }
       }
     }
   }
 `;
 function App() {
   const { loading, error, data } = useQuery(GET_PRODUCTS);
   const [cart, setCart] = useState([]);

   const addToCart = (product) =&amp;gt; {
     setCart([...cart, { ...product, quantity: 1 }]);
   };

   if (loading) return &amp;lt;p className="text-center mt-10"&amp;gt;Loading...&amp;lt;/p&amp;gt;;
   if (error) return &amp;lt;p className="text-center mt-10 text-red-500"&amp;gt;Error: {error.message}&amp;lt;/p&amp;gt;;

   const products = data.products.edges.map(({ node }) =&amp;gt; ({
     id: node.id,
     title: node.title,
     description: node.description,
     image: node.images.edges[0]?.node.src || '',
     price: node.variants.edges[0]?.node.priceV2?.amount,
     currency: node.variants.edges[0]?.node.priceV2?.currencyCode,
   }));

   return (
     &amp;lt;div className="container mx-auto p-4"&amp;gt;
       &amp;lt;h1 className="text-3xl font-bold mb-6 text-center"&amp;gt;My Shopify Store&amp;lt;/h1&amp;gt;
       &amp;lt;div className="flex"&amp;gt;
         &amp;lt;div className="w-3/4"&amp;gt;
           &amp;lt;ProductList products={products} addToCart={addToCart} /&amp;gt;
         &amp;lt;/div&amp;gt;
         &amp;lt;div className="w-1/4"&amp;gt;
           &amp;lt;Cart cart={cart} /&amp;gt;
         &amp;lt;/div&amp;gt;
       &amp;lt;/div&amp;gt;
     &amp;lt;/div&amp;gt;
   );
       }

 export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What code does it do?&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Defines a GraphQL query (&lt;code&gt;GET_PRODUCTS&lt;/code&gt;) to fetch 10 products with their details (ID, title, image, price, etc.).&lt;/li&gt;
&lt;li&gt;Uses &lt;code&gt;useQuery&lt;/code&gt; to run the query when the app loads.&lt;/li&gt;
&lt;li&gt;Manages a &lt;code&gt;cart&lt;/code&gt; state with &lt;code&gt;useState&lt;/code&gt; to store added products.&lt;/li&gt;
&lt;li&gt;Shows a loading message while fetching data or an error if something goes wrong.&lt;/li&gt;
&lt;li&gt;Maps the API data into a simple product list and passes it to &lt;code&gt;ProductList&lt;/code&gt; and &lt;code&gt;Cart&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Create the Product CardList Component&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Create a folder &lt;code&gt;src/components&lt;/code&gt; if it doesn’t exist.&lt;/li&gt;
&lt;li&gt;Create &lt;code&gt;src/components/ProductList.jsx&lt;/code&gt;:&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
import React from 'react';&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; function ProductList({ products, addToCart }) {
   return (
     &amp;lt;div className="grid grid-cols-3 gap-4"&amp;gt;
       {products.map((product) =&amp;gt; (
         &amp;lt;div key={product.id} className="border p-4 rounded-lg shadow-md"&amp;gt;
           &amp;lt;img src={product.image} alt={product.title} className="w-full h-48 object-cover mb-4" /&amp;gt;
           &amp;lt;h2 className="text-xl font-semibold"&amp;gt;{product.title}&amp;lt;/h2&amp;gt;
           &amp;lt;p className="text-gray-600"&amp;gt;{product.description.slice(0, 100)}...&amp;lt;/p&amp;gt;
           &amp;lt;p className="text-lg font-bold mt-2"&amp;gt;
             {product.price} {product.currency}
           &amp;lt;/p&amp;gt;
           &amp;lt;button
             onClick={() =&amp;gt; addToCart(product)}
             className="mt-4 bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600"
           &amp;gt;
             Add to Cart
           &amp;lt;/button&amp;gt;
         &amp;lt;/div&amp;gt;
       ))}
     &amp;lt;/div&amp;gt;
   );
 }

 export default ProductList;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;What does it do?&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Takes a list of &lt;code&gt;products&lt;/code&gt; and an &lt;code&gt;addToCart&lt;/code&gt; function as props.&lt;/li&gt;
&lt;li&gt;Displays each product in a card with an image, title, description (shortened to 100 characters), and price.&lt;/li&gt;
&lt;li&gt;Includes an “Add to Cart” button that calls &lt;code&gt;addToCart&lt;/code&gt; with the product details.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Create the Cart Component&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Create &lt;code&gt;src/components/Cart.jsx&lt;/code&gt;:&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
import React from 'react';&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; function Cart({ cart }) {
   const total = cart.reduce((sum, item) =&amp;gt; sum + parseFloat(item.price), 0).toFixed(2);

   return (
     &amp;lt;div className="border p-4 rounded-lg shadow-md"&amp;gt;
       &amp;lt;h2 className="text-xl font-semibold mb-4"&amp;gt;Cart&amp;lt;/h2&amp;gt;
       {cart.length === 0 ? (
         &amp;lt;p className="text-gray-600"&amp;gt;Your cart is empty.&amp;lt;/p&amp;gt;
       ) : (
         &amp;lt;&amp;gt;
           {cart.map((item, index) =&amp;gt; (
             &amp;lt;div key={index} className="flex justify-between mb-2"&amp;gt;
               &amp;lt;span&amp;gt;{item.title}&amp;lt;/span&amp;gt;
               &amp;lt;span&amp;gt;{item.price} {item.currency}&amp;lt;/span&amp;gt;
             &amp;lt;/div&amp;gt;
           ))}
           &amp;lt;hr className="my-4" /&amp;gt;
           &amp;lt;div className="flex justify-between font-bold"&amp;gt;
             &amp;lt;span&amp;gt;Total:&amp;lt;/span&amp;gt;
             &amp;lt;span&amp;gt;{total} {cart[0]?.currency || ''}&amp;lt;/span&amp;gt;
           &amp;lt;/div&amp;gt;
         &amp;lt;/&amp;gt;
       )}
     &amp;lt;/div&amp;gt;
   );
 }

 export default Cart;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;What does it do?&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Takes a &lt;code&gt;cart&lt;/code&gt; array as a prop.&lt;/li&gt;
&lt;li&gt;Shows a list of items in the cart with their prices.&lt;/li&gt;
&lt;li&gt;Calculates and displays the total price.&lt;/li&gt;
&lt;li&gt;Displays “Your cart is empty” if the cart is empty.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Update the HTML File&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Replace &lt;code&gt;index.html&lt;/code&gt; with:&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
&amp;lt;!DOCTYPE html&amp;gt;&lt;br&gt;
&amp;lt;html lang="en"&amp;gt;&lt;br&gt;
&amp;lt;head&amp;gt;&lt;br&gt;
  &amp;lt;meta charset="UTF-8" /&amp;gt;&lt;br&gt;
  &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0" /&amp;gt;&lt;br&gt;
  &amp;lt;meta name="description" content="My Shopify Storefront" /&amp;gt;&lt;br&gt;
  &amp;lt;title&amp;gt;My Shopify Storefront&amp;lt;/title&amp;gt;&lt;br&gt;
  &amp;lt;!-- Favicon for better branding --&amp;gt;&lt;br&gt;
  &amp;lt;link rel="icon" type="image/x-icon" href="/favicon.ico" /&amp;gt;&lt;br&gt;
  &amp;lt;!-- Tailwind CSS CDN (unchanged, but consider production alternatives) --&amp;gt;&lt;br&gt;
  &amp;lt;script src="https://cdn.tailwindcss.com"&amp;gt;&amp;lt;/script&amp;gt;&lt;br&gt;
&amp;lt;/head&amp;gt;&lt;br&gt;
&amp;lt;body&amp;gt;&lt;br&gt;
  &amp;lt;!-- Root element for React rendering --&amp;gt;&lt;br&gt;
  &amp;lt;div id="root"&amp;gt;&amp;lt;/div&amp;gt;&lt;br&gt;
  &amp;lt;!-- Ensure JavaScript module is loaded correctly --&amp;gt;&lt;br&gt;
  &amp;lt;script type="module" src="/src/main.jsx"&amp;gt;&amp;lt;/script&amp;gt;&lt;br&gt;
&amp;lt;/body&amp;gt;&lt;br&gt;
&amp;lt;/html&amp;gt;&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This sets up the HTML structure and includes Tailwind CSS via CDN.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 5: Run and Test Your Storefront
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Start the Server&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In your terminal, run:
&lt;code&gt;&lt;/code&gt;&lt;code&gt;bash
npm run dev
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Open &lt;code&gt;http://localhost:5173&lt;/code&gt; in your browser.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;What You’ll See&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A header saying “My Shopify Store.”&lt;/li&gt;
&lt;li&gt;A grid of product cards with images, titles, descriptions, prices, and “Add to Cart” buttons.&lt;/li&gt;
&lt;li&gt;A cart on the right showing added items and a total price.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Test It Out&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click “Add to Cart” on a product. They should appear in the cart.&lt;/li&gt;
&lt;li&gt;If you see “Loading…” or an error, double-check:

&lt;ul&gt;
&lt;li&gt;Your Shopify API token and store domain in &lt;code&gt;main.jsx&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;That your Shopify store has products with images and prices.&lt;/li&gt;
&lt;li&gt;That your internet connection is stable.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Step 6: Deploy Your Storefront
&lt;/h3&gt;

&lt;p&gt;Once your storefront looks good, you can share it online using a hosting service like Vercel or Netlify.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Prepare for Deployment&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Store your Shopify API token in a &lt;code&gt;.env&lt;/code&gt; file for security:
&lt;code&gt;&lt;/code&gt;&lt;code&gt;
env
VITE_SHOPIFY_API_TOKEN=your-storefront-api-token
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Update &lt;code&gt;main.jsx&lt;/code&gt; to use the environment variable:
&lt;code&gt;&lt;/code&gt;&lt;code&gt;
javascript
headers: {
'X-Shopify-Storefront-Access-Token': process.env.VITE_SHOPIFY_API_TOKEN,
},
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Deploy to Vercel&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sign up at &lt;a href="https://vercel.com" rel="noopener noreferrer"&gt;vercel.com&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Install Vercel CLI:
&lt;code&gt;&lt;/code&gt;&lt;code&gt;
npm install -g vercel
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Run:
&lt;code&gt;&lt;/code&gt;&lt;code&gt;bash
vercel
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Follow the prompts to link your project and deploy.&lt;/li&gt;
&lt;li&gt;Add your &lt;code&gt;VITE_SHOPIFY_API_TOKEN&lt;/code&gt; to Vercel’s environment variables in their dashboard.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Test Your Live Site&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Vercel provides a URL (e.g., &lt;code&gt;your-app-name.vercel.app&lt;/code&gt;). Open it to see your live storefront!&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Taking Your Storefront to the Next Level
&lt;/h2&gt;

&lt;p&gt;Your storefront is now functional, but there are ways to make it even better:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Add Product Pages&lt;/strong&gt;: Use React Router to create individual product pages.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Improve the Cart&lt;/strong&gt;: Allow users to update quantities or remove items.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Add Checkout&lt;/strong&gt;: Use Shopify’s checkout API to process payments.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Polish the Design&lt;/strong&gt;: Customize Tailwind’s classes or add animations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Optimize for Mobile&lt;/strong&gt;: Test your site on phones and tweak the CSS for responsiveness.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If this feels like a lot, consider reaching out to a &lt;a href="https://www.shopify.com/partners" rel="noopener noreferrer"&gt;Shopify Expert agency&lt;/a&gt; to help refine and scale your store. They can handle complex integrations and ensure a professional finish.&lt;/p&gt;

&lt;h2&gt;
  
  
  Need Help? Hire Experts
&lt;/h2&gt;

&lt;p&gt;Building a custom storefront is a big project, especially if you want advanced features like custom animations or subscriptions. If you’re ready to take your store to the next level, you can &lt;a href="https://www.lucentinnovation.com/pages/hire-reactjs-developers" rel="noopener noreferrer"&gt;Hire dedicated ReactJS developers&lt;/a&gt; to bring your vision to life. They can code faster, handle bugs, and add cool features like real-time inventory updates.&lt;/p&gt;

&lt;h2&gt;
  
  
  Troubleshooting Tips
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;No Products Show Up?&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Check your API token and store domain in &lt;code&gt;main.jsx&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Ensure your Shopify store has products with images and prices.&lt;/li&gt;
&lt;li&gt;Look at the browser’s “Console” tab (right-click &amp;gt; Inspect) for errors).&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Styles Look Weird?&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Make sure Tailwind CSS is included in &lt;code&gt;index.html&lt;/code&gt; or &lt;code&gt;index.css&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Clear your browser cache or try a different browser).&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;API Errors?&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Test your Shopify API in GraphiQL to confirm it’s working.&lt;/li&gt;
&lt;li&gt;Verify your API token has Storefront permissions.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;You’ve just built a custom Shopify storefront with React.js! You learned how to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Set up a Shopify store and Storefront API.&lt;/li&gt;
&lt;li&gt;Create a React project with Tailwind CSS and Vite- Connect to Shopify’s API with Apollo Client.&lt;/li&gt;
&lt;li&gt;Build components for products and a cart to fetch products and manage a cart.&lt;/li&gt;
&lt;li&gt;Deploy your app to Vercel.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is just the beginning. With practice, you can add more features and make your store stand out!. If you’re feeling stuck or want to go big, a &lt;a href="https://www.lucentinnovation.com/pages/shopify-experts" rel="noopener noreferrer"&gt;Shopify Expert agency&lt;/a&gt; can guide you, or you can Hire dedicated ReactJS developers to supercharge your project. Keep coding, experimenting, and have fun building your dream store!&lt;/p&gt;

</description>
      <category>shopify</category>
      <category>react</category>
      <category>shopifystorefront</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Building Scalable React Apps: Best Practices for Performance and Maintainability</title>
      <dc:creator>Elias Garcia</dc:creator>
      <pubDate>Mon, 16 Jun 2025 10:16:33 +0000</pubDate>
      <link>https://dev.to/deep_raval_16fa6674dda823/building-scalable-react-apps-best-practices-for-performance-and-maintainability-5cmc</link>
      <guid>https://dev.to/deep_raval_16fa6674dda823/building-scalable-react-apps-best-practices-for-performance-and-maintainability-5cmc</guid>
      <description>&lt;p&gt;As all businesses want their web applications to grow with the company, you might expect the same from it. You want your React app to handle more users and remain easy to manage for your team.  &lt;/p&gt;

&lt;p&gt;A scalable React app is the answer to your vision.  &lt;/p&gt;

&lt;p&gt;A web app built with React.js is easy to scale with your organization’s growth and easy to maintain.  &lt;/p&gt;

&lt;p&gt;This article guides you through the key practices for creating scalable React apps. We will consider performance and maintainability while developing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Best Practices for Scalable React Apps
&lt;/h2&gt;

&lt;p&gt;Here are a few tested and proven strategies to ensure that your React app can grow efficiently with time and remain easy to manage.  &lt;/p&gt;

&lt;h3&gt;
  
  
  1. Organize Code into Small, Reusable Parts (Modular Architecture)
&lt;/h3&gt;

&lt;p&gt;Small, independent pieces in the app are called components. Break your app into small components. Each component handles one task, such as displaying a button or product list. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why it helps:&lt;/strong&gt; When there is an issue in the app. Small components act like building blocks. They ca be easily reused, updated or replaced without affecting the whole app. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; A &lt;code&gt;Button&lt;/code&gt; component can be used across your app for actions like “Buy Now” or “Sign Up.”&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Button() {
  return &amp;lt;button&amp;gt;Click me!&amp;lt;/button&amp;gt;;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Organize components in folders like src/components/Button or src/features/Products to keep code tidy and manageable.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqxdnlaw7t7pu2bpteel9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqxdnlaw7t7pu2bpteel9.png" alt="React Component Architecture" width="800" height="202"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Keep Components Focused (Single Responsibility)
&lt;/h3&gt;

&lt;p&gt;Each of the components should be focused on one task. This keeps your React app simple and easier for your team to work on.&lt;br&gt;
&lt;strong&gt;Example:&lt;/strong&gt; Split a complex feature into two components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;ProductListContainer:&lt;/strong&gt; Fetches the list of products from a server.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ProductList:&lt;/strong&gt; Displays the products on the screen.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function UserListContainer() {
  const users = ["Alice", "Bob", "Charlie"];
  return &amp;lt;UserList users={users} /&amp;gt;;
}

function UserList({ users }) {
  return (
    &amp;lt;ul&amp;gt;
      {users.map((user) =&amp;gt; (
        &amp;lt;li&amp;gt;{user}&amp;lt;/li&amp;gt;
      ))}
    &amp;lt;/ul&amp;gt;
  );
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This way, changes to how products are displayed don’t affect how they’re fetched. With that, your &lt;a href="https://www.lucentinnovation.com/pages/hire-reactjs-developers" rel="noopener noreferrer"&gt;expert ReactJS developer&lt;/a&gt;’s time is saved.&lt;/p&gt;
&lt;h3&gt;
  
  
  3. Manage Data Efficiently (State Management)
&lt;/h3&gt;

&lt;p&gt;Your app tracks information of the user and shopping cart items. It is called state. For smaller apps, React’s built-in tools like &lt;code&gt;useState&lt;/code&gt; or &lt;code&gt;Context&lt;/code&gt; work well. But for larger apps, tools like Zustand can help you simplify managing data across many components. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why it helps:&lt;/strong&gt; Efficient state management can keep your app fast and organized, even as it grows. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; Use Context to share a user’s name across the app.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const UserContext = React.createContext();

function App() {
  const user = "Alice";
  return (
    &amp;lt;UserContext.Provider value={user}&amp;gt;
      &amp;lt;Profile /&amp;gt;
    &amp;lt;/UserContext.Provider&amp;gt;
  );
}

function Profile() {
  const user = React.useContext(UserContext);
  return &amp;lt;h1&amp;gt;Hello, {user}!&amp;lt;/h1&amp;gt;;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This approach ensures all parts of the app can access shared data without confusion.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvwg9j8r48oi7ofa6szx7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvwg9j8r48oi7ofa6szx7.png" alt="State Management in React" width="800" height="242"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Boost Performance &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A fast app will keep your users happy and reduce bounce rates. Here are the key techniques: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Lazy Loading:&lt;/strong&gt; Load only the parts of the app that users need right now, like loading only the homepage first.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Memoization:&lt;/strong&gt; Save the results of complex tasks to avoid repeating them. Use &lt;code&gt;React.memo&lt;/code&gt; to prevent unnecessary component updates.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const FastComponent = React.memo(() =&amp;gt; {
  return &amp;lt;div&amp;gt;This won’t redraw unless it needs to!&amp;lt;/div&amp;gt;;
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Virtualization:&lt;/strong&gt; For long lists (like 1,000 products), display only what’s on the screen to save resources.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These methods ensure your app runs smoothly, even with heavy traffic.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Test Thoroughly
&lt;/h3&gt;

&lt;p&gt;Testing ensures your app works as expected, reducing bugs and customer complaints. Use tools like Jest to check if components display correctly. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; Test a button to confirm it appears on the screen.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { render, screen } from '@testing-library/react'; 

test('shows button', () =&amp;gt; { 
  render(&amp;lt;Button label="Click me" /&amp;gt;); 
  expect(screen.getByText('Click me')).toBeInTheDocument(); 
}); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Testing saves time and money by catching issues early. You can explore &lt;a href="https://www.linkedin.com/pulse/reactjs-development-challenges-2025-performance-seo-deep-raval-xykic/" rel="noopener noreferrer"&gt;React challenges and solutions&lt;/a&gt; to understand the proper strategies to keep your React app up and functioning without any hurdles.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5ibxzytubnywxk7izino.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5ibxzytubnywxk7izino.png" alt="React js testing strategies" width="800" height="343"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Ensure Accessibility
&lt;/h3&gt;

&lt;p&gt;Your app should be usable by everyone, including those with disabilities. Use clear HTML and add labels for screen readers to improve user experience and meet legal standards. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Example:&lt;/strong&gt; Add a label to a button for accessibility.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function AccessibleButton() { 
  return &amp;lt;button aria-label="Send message"&amp;gt;Send&amp;lt;/button&amp;gt;; 
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This makes your app inclusive and boosts its reputation. &lt;/p&gt;

&lt;h3&gt;
  
  
  7. Leverage Modern Tools
&lt;/h3&gt;

&lt;p&gt;Modern tools streamline development and improve performance. Consider these: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Next.js:&lt;/strong&gt; Enhances app speed and search engine visibility with server-side rendering. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;React Query:&lt;/strong&gt; Simplifies fetching data from servers, like product lists. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Vite:&lt;/strong&gt; Speeds up development by bundling code efficiently.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These tools help your team build faster and deliver a better product.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why This Matters for Your Business
&lt;/h2&gt;

&lt;p&gt;Following these standard Reactjs best practices will confirm that your business app functions smoothly, scales with growth, saves your team’s time and costs, improves user satisfaction, and stays competitive in the modern world.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Now you know that it’s not tough to understand, but actually executing it could be. So, I suggest you get in touch with a &lt;a href="https://www.lucentinnovation.com/services/reactjs-development" rel="noopener noreferrer"&gt;React.js development company&lt;/a&gt;. They can build a React app that meets your requirements.  &lt;/p&gt;

&lt;p&gt;Keeping these steps by your side will help you create an app to grow your business.   &lt;/p&gt;

</description>
      <category>react</category>
      <category>reactapp</category>
      <category>bestpractices</category>
      <category>scalableapplication</category>
    </item>
    <item>
      <title>Step-by-Step Guide to Building Your First React JS Application with Node.js</title>
      <dc:creator>Elias Garcia</dc:creator>
      <pubDate>Mon, 09 Jun 2025 09:33:27 +0000</pubDate>
      <link>https://dev.to/deep_raval_16fa6674dda823/step-by-step-guide-to-building-your-first-react-js-application-with-nodejs-505g</link>
      <guid>https://dev.to/deep_raval_16fa6674dda823/step-by-step-guide-to-building-your-first-react-js-application-with-nodejs-505g</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;These steps will help you build a simple to-do list app with React.js for the front end and Node.js for the back end. We will use Node.js with Express to ensure it works quickly.  &lt;/p&gt;

&lt;p&gt;By following these steps as you read, you will have a fully functional app that users can use to add and view tasks.  &lt;/p&gt;

&lt;p&gt;First, make sure you have the prerequisites needed for this task. &lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Node.js and npm:&lt;/strong&gt; Install Node.js (version 14 or higher) and npm from nodejs.org. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Basic knowledge:&lt;/strong&gt; Familiarity with JavaScript, HTML, and CSS. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Text editor:&lt;/strong&gt; Use VS Code or any preferred editor. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Terminal:&lt;/strong&gt; For running commands.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Lay the Foundation with Your Project Structure
&lt;/h2&gt;

&lt;p&gt;The first task we will proceed with is creating a home for our app. Open your terminal and make a new project folder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir todo-app 
cd todo-app 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Initialize it with a quick command to generate a &lt;code&gt;package.json&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm init -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let’s carve out a space for the backend. Create a &lt;code&gt;server&lt;/code&gt; folder and set it up:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir server 
cd server 
npm init -y 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hop back to the main folder and conjure up a React frontend with one magical command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd .. 
npx create-react-app client 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you have your &lt;code&gt;client&lt;/code&gt; folder for the frontend, and a &lt;code&gt;server&lt;/code&gt; folder for the backend.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Power Up the Node.js Backend
&lt;/h2&gt;

&lt;p&gt;Second steps includes the process of &lt;a href="https://www.lucentinnovation.com/services/nodejs-development" rel="noopener noreferrer"&gt;backend development with Node.js&lt;/a&gt;. For that, navigate to the server folder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd server 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install Express for our server and CORS. This installation will allow interaction between the frontend and the backend.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install express cors 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create an &lt;code&gt;index.js&lt;/code&gt; file and add this code to set up a simple API:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require('express'); 
const cors = require('cors'); 
const app = express(); 
const port = 5000; 

app.use(express.json()); 
app.use(cors()); 

let tasks = []; 

app.get('/api/tasks', (req, res) =&amp;gt; { 
  res.json(tasks); 
}); 

app.post('/api/tasks', (req, res) =&amp;gt; { 
  const task = { id: tasks.length + 1, text: req.body.text }; 
  tasks.push(task); 
  res.json(task); 
}); 

app.listen(port, () =&amp;gt; { 
  console.log(`Server running on http://localhost:${port}`); 
}); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Fire up the server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node index.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Go to &lt;code&gt;http://localhost:5000/api/tasks&lt;/code&gt; in your browser. You will see an empty array &lt;code&gt;[]&lt;/code&gt;, it means that your backend is alive now! &lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Craft a Sleek React Frontend
&lt;/h2&gt;

&lt;p&gt;After making your backend alive, it’s time to make your frontend lively. Switch to the &lt;code&gt;client&lt;/code&gt; folder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ../client
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install Axios to handle HTTP requests:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install axios 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open &lt;code&gt;src/App.js&lt;/code&gt; and replace its contents with this code to create a vibrant to-do list:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState, useEffect } from 'react'; 
import axios from 'axios'; 
import './App.css'; 

function App() { 
  const [tasks, setTasks] = useState([]); 
  const [newTask, setNewTask] = useState(''); 

  useEffect(() =&amp;gt; { 
    axios.get('http://localhost:5000/api/tasks') 
      .then(response =&amp;gt; setTasks(response.data)) 
      .catch(error =&amp;gt; console.error('Error fetching tasks:', error)); 
  }, []); 

  const addTask = () =&amp;gt; { 
    if (!newTask.trim()) return; 
    axios.post('http://localhost:5000/api/tasks', { text: newTask }) 
      .then(response =&amp;gt; { 
        setTasks([...tasks, response.data]); 
        setNewTask(''); 
      }) 
      .catch(error =&amp;gt; console.error('Error adding task:', error)); 
  }; 

  return ( 
    &amp;lt;div className="App"&amp;gt; 
      &amp;lt;h1&amp;gt;To-Do List&amp;lt;/h1&amp;gt; 
      &amp;lt;div&amp;gt; 
        &amp;lt;input 
          type="text" 
          value={newTask} 
          onChange={(e) =&amp;gt; setNewTask(e.target.value)} 
          placeholder="Enter a new task" 
        /&amp;gt; 
        &amp;lt;button onClick={addTask}&amp;gt;Add Task&amp;lt;/button&amp;gt; 
      &amp;lt;/div&amp;gt; 
      &amp;lt;ul&amp;gt; 
        {tasks.map(task =&amp;gt; ( 
          &amp;lt;li key={task.id}&amp;gt;{task.text}&amp;lt;/li&amp;gt; 
        ))} 
      &amp;lt;/ul&amp;gt; 
    &amp;lt;/div&amp;gt; 
  ); 
} 

export default App; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, make it attractive by updating &lt;code&gt;src/App.css&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.App { 
  text-align: center; 
  max-width: 600px; 
  margin: 0 auto; 
  padding: 20px; 
} 

h1 { 
  color: #333; 
} 

input { 
  padding: 10px; 
  margin-right: 10px; 
  width: 200px; 
} 

button { 
  padding: 10px 20px; 
  background-color: #007bff; 
  color: white; 
  border: none; 
  cursor: pointer; 
} 

button:hover { 
  background-color: #0056b3; 
} 

ul { 
  list-style: none; 
  padding: 0; 
} 

li { 
  padding: 10px; 
  border-bottom: 1px solid #ccc; 
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now your frontend is ready to dominate! &lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Launch Your Full-Stack App
&lt;/h2&gt;

&lt;p&gt;Let’s bring it everything together! First, keep your backend running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ../server 
node index.js 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open a new terminal, head to the &lt;code&gt;client&lt;/code&gt; folder, and start the React app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ../client 
npm start 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your browser should pop open at &lt;code&gt;http://localhost:3000&lt;/code&gt;. Type a task, hit “Add Task,” and watch it appear in the list! &lt;em&gt;(&lt;strong&gt;Tip:&lt;/strong&gt; tasks vanish when the server restarts since we’re currently using in-memory storage.)&lt;/em&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Take It to the World (Optional Deployment)
&lt;/h2&gt;

&lt;p&gt;You didn't create the app just for yourself, right? Deploy your app on platforms like Heroku or Render for the backend. Swap the in-memory &lt;code&gt;tasks&lt;/code&gt; array for a database like MongoDB to keep tasks persistent. &lt;/p&gt;

&lt;p&gt;For the frontend, &lt;a href="https://www.lucentinnovation.com/services/reactjs-development" rel="noopener noreferrer"&gt;build your React.js app&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd client 
npm run build 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can host the build folder on Netlify or Vercel, or you can serve it via Express. Make sure to update the API URLs in &lt;code&gt;App.js&lt;/code&gt; to point to your live backend. &lt;/p&gt;

&lt;p&gt;Congratulations, your app is now ready to steal the spotlight. &lt;/p&gt;

&lt;p&gt;Your Project’s Blueprint &lt;/p&gt;

&lt;p&gt;Here’s how your project looks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;todo-app/ 
├── client/              # React frontend 
│   ├── src/ 
│   │   ├── App.js 
│   │   └── App.css 
│   └── package.json 
├── server/              # Node.js backend 
│   ├── index.js 
│   └── package.json 
└── package.json 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Clean and organized—ready for future upgrades! &lt;/p&gt;

&lt;h2&gt;
  
  
  Level Up Your App
&lt;/h2&gt;

&lt;p&gt;You can level up your app with no force! Here are the quick steps to make your app look even better:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Connect a database to save tasks permanently.
&lt;/li&gt;
&lt;li&gt;Add edit and delete buttons for functions.
&lt;/li&gt;
&lt;li&gt;Style it up with Tailwind CSS or Material-UI.
&lt;/li&gt;
&lt;li&gt;Secure it with user authentication.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Yayy! You Did It!
&lt;/h2&gt;

&lt;p&gt;In my previous article, I shared steps to use &lt;a href="https://dev.to/deep_raval_16fa6674dda823/seo-friendly-e-commerce-site-in-5-steps-with-react-and-nextjs-3g0i"&gt;React and Next.js to build an e-commerce site&lt;/a&gt; that is SEO friendly. If you are from the e-commerce sector, you should refer that article.&lt;/p&gt;

&lt;p&gt;You didn’t just build a full-stack to-do list app; you built the most attractive-looking app from scratch using React.js and Node.js. &lt;/p&gt;

&lt;p&gt;Using React in the front will ensure that it is lively and that users can find it interactive. Using Node.js and Express will help keep your backend robust and smooth.  &lt;/p&gt;

&lt;p&gt;This project was an introductory-level project that you can add to your portfolio. But make sure you don’t stop learning and developing new projects. The world of full-stack development is ever-evolving, and you’ll have to match the pace with it.&lt;/p&gt;

&lt;p&gt;Good luck! &lt;/p&gt;

</description>
      <category>react</category>
      <category>node</category>
      <category>reactapp</category>
      <category>appdevelopment</category>
    </item>
    <item>
      <title>SEO-Friendly E-commerce site in 5 Steps with React and Next.js</title>
      <dc:creator>Elias Garcia</dc:creator>
      <pubDate>Thu, 05 Jun 2025 07:46:38 +0000</pubDate>
      <link>https://dev.to/deep_raval_16fa6674dda823/seo-friendly-e-commerce-site-in-5-steps-with-react-and-nextjs-3g0i</link>
      <guid>https://dev.to/deep_raval_16fa6674dda823/seo-friendly-e-commerce-site-in-5-steps-with-react-and-nextjs-3g0i</guid>
      <description>&lt;p&gt;High-performance and scalability matters the most for any e-commerce site. Combination of React and Next.js is a powerful stack to address these concerns and build an SEO-friendly e-commerce website. &lt;br&gt;
React’s modular, component-based architecture takes care of the dynamic and interactive user interfaces (UIs). Meanwhile, Next.js focuses on improving the performance with server-side rendering (SSR), static site generation (SSG), and built-in routing. Don’t worry about these technical terms; I’ll explain them all in detail as we dive deeper. &lt;br&gt;
The main focus of this blog is to assist you with the 5-step process for building an e-commerce site optimized for the factors that matter most to you: SEO, performance, and security.&lt;/p&gt;
&lt;h2&gt;
  
  
  Why React.js and Next.js for E-Commerce?
&lt;/h2&gt;

&lt;p&gt;React.js is a JavaScript library that is widely used among different industries. When you want to develop an interactive user interfaces, React allows to use their reusable componenets and virtual DOM for fast updates.&lt;br&gt;
Next.js is a React framework that extends React's capabilities to develop production-ready applications. It offers server-side rendering, static site generation, and file-system-based routing to improve site performance and support technical SEO efforts.&lt;br&gt;
In short, React handles the "What" of UI, and Next.js provides the "How" for a complete, optimized web app.&lt;br&gt;
Let me explain you this terms; SSR, SSG, and file-system-based routing and its importance for Ecommerce, in short and quickly so we don’t deviate from the focus of the article.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- Server-Side Rendering (SSR):&lt;/strong&gt;&lt;br&gt;
 Before your site appears on the customer’s browser, your website’s conent will be fully rendered on the server. &lt;br&gt;
It matters for e-commerce for faster loading as the customers see product pages instantly without any delay. SSR makes the crawling of information easy for the search bots and that helps to improve your site’s ranking on Google. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- Static Site Generation (SSG):&lt;/strong&gt;&lt;br&gt;
 We don’t keep optimizing brand related pages like About Us, Privacy Policy, Our Team, and Our Process. With SSG, we can develop pages that can be delivered instantly when a user clicks on it. &lt;br&gt;
SSG becomes important as it delivers unmatched speed and reliability even during high traffic. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- File-System-Based Routing:&lt;/strong&gt;&lt;br&gt;
 For e-commerce sites, creation of new products is a task that is often performed. With File-System-Based routing, we can create new pages on your website with little to no effort; the system automatically generates the URL for that page. &lt;br&gt;
We can develop and launch new products or collection pages quickly with File-System-Based routing. It also helps to keep the website well-organized. &lt;br&gt;
Now let’s get started with the development of E-commerce site. If there is any step that you are stuck at, feel free to comment and let me know. I’ll respond in a jify.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 1: Set Up Your Next.js Project
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal:&lt;/strong&gt; Initialize a Next.js project with essential dependencies for an e-commerce site.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Install Node.js:&lt;/strong&gt; Ensure Node.js (v16 or later) and npm are installed. Download from &lt;a href="https://nodejs.org/" rel="noopener noreferrer"&gt;nodejs.org&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create a Next.js App:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-next-app@latest my-ecommerce-site
cd my-ecommerce-site
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Select TypeScript for type safety (optional).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Install Dependencies:&lt;/strong&gt;&lt;br&gt;
Tailwind CSS for responsive styling:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In &lt;code&gt;tailwind.config.js&lt;/code&gt;, add:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module.exports = {
  content: ['./pages/**/*.{js,ts,jsx,tsx}', './components/**/*.{js,ts,jsx,tsx}'],
  theme: { extend: {} },
  plugins: [],
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In &lt;code&gt;styles/globals.css&lt;/code&gt;, add:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@tailwind base;
@tailwind components;
@tailwind utilities;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Axios for API calls:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install axios
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Start the Development Server:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verify at &lt;a href="http://localhost:3000" rel="noopener noreferrer"&gt;http://localhost:3000&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;SEO Tip:&lt;/strong&gt; Next.js’s clean URLs and built-in  component simplify meta tag management for SEO.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Create a Mock Product API
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal:&lt;/strong&gt; Set up a mock product database and API for product listings.&lt;br&gt;
&lt;strong&gt;Mock Product Data:&lt;/strong&gt; Create &lt;code&gt;data/products.js&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const products = [
  { id: 1, name: "Laptop", price: 999, description: "High-performance laptop for professionals", image: "/images/laptop.jpg", category: "Electronics" },
  { id: 2, name: "Headphones", price: 99, description: "Wireless noise-canceling headphones", image: "/images/headphones.jpg", category: "Accessories" },
  { id: 3, name: "Smartphone", price: 699, description: "Latest 5G smartphone", image: "/images/smartphone.jpg", category: "Electronics" },
];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Create an API Route:&lt;/strong&gt; In &lt;code&gt;pages/api/products.js&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default function handler(req, res) {
  const products = require('../../data/products').products;
  res.status(200).json(products);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Test at &lt;a href="http://localhost:3000/api/products" rel="noopener noreferrer"&gt;http://localhost:3000/api/products&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;SEO Tip:&lt;/strong&gt; Use descriptive product names, categories, and descriptions to improve keyword relevance and indexing.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Build the Product Listing Page
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal:&lt;/strong&gt; Create a homepage to display products using reusable React components.&lt;br&gt;
&lt;strong&gt;Create a ProductCard Component:&lt;/strong&gt; In &lt;code&gt;components/ProductCard.js&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Image from 'next/image';
import Link from 'next/link';

export default function ProductCard({ product }) {
  return (
    &amp;lt;Link href={`/products/${product.id}`}&amp;gt;
      &amp;lt;div className="border p-4 rounded shadow hover:shadow-lg transition cursor-pointer"&amp;gt;
        &amp;lt;Image
          src={product.image}
          alt={product.name}
          width={200}
          height={200}
          className="object-cover rounded"
          priority
        /&amp;gt;
        &amp;lt;h2 className="text-xl font-bold mt-2"&amp;gt;{product.name}&amp;lt;/h2&amp;gt;
        &amp;lt;p className="text-gray-600"&amp;gt;{product.description}&amp;lt;/p&amp;gt;
        &amp;lt;p className="text-green-600 font-semibold"&amp;gt;${product.price}&amp;lt;/p&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/Link&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Update the Homepage:&lt;/strong&gt; In &lt;code&gt;pages/index.js&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useEffect, useState } from 'react';
import axios from 'axios';
import Head from 'next/head';
import ProductCard from '../components/ProductCard';

export default function Home() {
  const [products, setProducts] = useState([]);

  useEffect(() =&amp;gt; {
    axios.get('/api/products').then((res) =&amp;gt; setProducts(res.data));
  }, []);

  return (
    &amp;lt;div className="container mx-auto p-4"&amp;gt;
      &amp;lt;Head&amp;gt;
        &amp;lt;title&amp;gt;ShopNow - Online Store&amp;lt;/title&amp;gt;
        &amp;lt;meta name="description" content="Explore laptops, headphones, and smartphones at ShopNow, your trusted e-commerce platform." /&amp;gt;
        &amp;lt;meta name="keywords" content="ecommerce, electronics, shopping, online store" /&amp;gt;
        &amp;lt;script type="application/ld+json"&amp;gt;
          {JSON.stringify({
            "@context": "https://schema.org",
            "@type": "WebSite",
            "name": "ShopNow",
            "url": "https://your-site.com",
          })}
        &amp;lt;/script&amp;gt;
      &amp;lt;/Head&amp;gt;
      &amp;lt;h1 className="text-3xl font-bold mb-6 text-center"&amp;gt;Welcome to ShopNow&amp;lt;/h1&amp;gt;
      &amp;lt;div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6"&amp;gt;
        {products.map((product) =&amp;gt; (
          &amp;lt;ProductCard key={product.id} product={product} /&amp;gt;
        ))}
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 4: Create Dynamic Product Pages
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal:&lt;/strong&gt; Build SEO-friendly product detail pages using Next.js dynamic routes and SSG.&lt;br&gt;
&lt;strong&gt;Create a Dynamic Route:&lt;/strong&gt; In &lt;code&gt;pages/products/[id].js&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { products } from '../../data/products';
import Image from 'next/image';
import Head from 'next/head';

export default function ProductPage({ product }) {
  return (
    &amp;lt;div className="container mx-auto p-4"&amp;gt;
      &amp;lt;Head&amp;gt;
        &amp;lt;title&amp;gt;{product.name} - ShopNow&amp;lt;/title&amp;gt;
        &amp;lt;meta name="description" content={product.description} /&amp;gt;
        &amp;lt;meta name="keywords" content={`${product.name}, ${product.category}, ecommerce`} /&amp;gt;
        &amp;lt;script type="application/ld+json"&amp;gt;
          {JSON.stringify({
            "@context": "https://schema.org",
            "@type": "Product",
            "name": product.name,
            "image": product.image,
            "description": product.description,
            "offers": {
              "@type": "Offer",
              "price": product.price,
              "priceCurrency": "USD",
            },
          })}
        &amp;lt;/script&amp;gt;
      &amp;lt;/Head&amp;gt;
      &amp;lt;div className="flex flex-col md:flex-row gap-6"&amp;gt;
        &amp;lt;Image
          src={product.image}
          alt={product.name}
          width={400}
          height={400}
          className="object-cover rounded"
          priority
        /&amp;gt;
        &amp;lt;div&amp;gt;
          &amp;lt;h1 className="text-2xl font-bold"&amp;gt;{product.name}&amp;lt;/h1&amp;gt;
          &amp;lt;p className="text-gray-600 mt-2"&amp;gt;{product.description}&amp;lt;/p&amp;gt;
          &amp;lt;p className="text-green-600 text-xl font-semibold mt-2"&amp;gt;${product.price}&amp;lt;/p&amp;gt;
          &amp;lt;button className="bg-blue-500 text-white px-4 py-2 rounded mt-4 hover:bg-blue-600"&amp;gt;
            Add to Cart
          &amp;lt;/button&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export async function getStaticPaths() {
  const paths = products.map((product) =&amp;gt; ({
    params: { id: product.id.toString() },
  }));
  return { paths, fallback: false };
}

export async function getStaticProps({ params }) {
  const product = products.find((p) =&amp;gt; p.id === parseInt(params.id));
  return { props: { product } };
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;&lt;strong&gt;SEO Tip:&lt;/strong&gt; Use SSG with &lt;code&gt;getStaticPaths&lt;/code&gt; and &lt;code&gt;getStaticProps&lt;/code&gt; to pre-render product pages, improving load times and SEO. Add Product schema markup for rich search results.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Optimize for SEO, Performance, and Security
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Goal:&lt;/strong&gt; Enhance the site with SEO, performance optimizations, and security best practices.&lt;br&gt;
&lt;strong&gt;Generate a Sitemap:&lt;/strong&gt; In &lt;code&gt;pages/sitemap.xml.js&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { products } from '../data/products';

export default function Sitemap() {}

export async function getServerSideProps({ res }) {
  const baseUrl = process.env.NEXT_PUBLIC_BASE_URL || 'https://your-site.com';
  const sitemap = `&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
    &amp;lt;urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"&amp;gt;
      &amp;lt;url&amp;gt;&amp;lt;loc&amp;gt;${baseUrl}&amp;lt;/loc&amp;gt;&amp;lt;/url&amp;gt;
      ${products
        .map((product) =&amp;gt; `&amp;lt;url&amp;gt;&amp;lt;loc&amp;gt;${baseUrl}/products/${product.id}&amp;lt;/loc&amp;gt;&amp;lt;/url&amp;gt;`)
        .join('')}
    &amp;lt;/urlset&amp;gt;`;
  res.setHeader('Content-Type', 'text/xml');
  res.write(sitemap);
  res.end();
  return { props: {} };
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add &lt;code&gt;NEXT_PUBLIC_BASE_URL=https://your-site.com&lt;/code&gt; to &lt;code&gt;.env.local&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create Robots.txt:&lt;/strong&gt; In &lt;code&gt;public/robots.txt&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User-agent: *
Allow: /
Sitemap: https://your-site.com/sitemap.xml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Image Optimization:&lt;/strong&gt; Use Next.js’s &lt;code&gt;&amp;lt;Image&amp;gt;&lt;/code&gt; component with &lt;code&gt;priority&lt;/code&gt; and correct &lt;code&gt;width/height&lt;/code&gt; to leverage automatic WebP conversion and lazy loading.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Security Best Practices:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HTTPS: Ensure your site uses HTTPS (configured during deployment, e.g., via Vercel).&lt;/li&gt;
&lt;li&gt;Prevent XSS: Sanitize user inputs using libraries like DOMPurify if accepting user-generated content.&lt;/li&gt;
&lt;li&gt;Prevent CSRF: Use CSRF tokens in API requests (implement when adding cart functionality).&lt;/li&gt;
&lt;li&gt;Secure API: Validate requests in &lt;code&gt;getServerSideProps&lt;/code&gt; or API routes using JWT for authentication.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Performance Boost:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Automatic Code Splitting: Next.js splits JavaScript at the page level, loading only necessary code.&lt;/li&gt;
&lt;li&gt;Test with Lighthouse: Run audits in Chrome DevTools to optimize SEO, performance, and accessibility.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;SEO Tip: Submit the sitemap to Google Search Console and use tools like Ahrefs to monitor keyword performance.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Next Steps
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Add a Cart:&lt;/strong&gt; Use React Context or Redux to manage the cart state and persist data. &lt;br&gt;
&lt;strong&gt;Integrate Payments:&lt;/strong&gt; Add Stripe for secure checkout (see &lt;a href="https://stripe.com/docs" rel="noopener noreferrer"&gt;Stripe docs&lt;/a&gt;). &lt;br&gt;
&lt;strong&gt;Backend Integration:&lt;/strong&gt; Replace mock API with a database like MongoDB or a CMS like Strapi. &lt;br&gt;
Deploy: Use Vercel for seamless deployment and automatic scaling. &lt;br&gt;
&lt;strong&gt;Advanced SEO:&lt;/strong&gt; Implement breadcrumb navigation and additional schema.org markup (e.g., BreadcrumbList). &lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://dev.to/refine/nextjs-vs-react-a-beginners-guide-5607"&gt;React.js and Next.js&lt;/a&gt; form a robust stack for building SEO-friendly, high-performance e-commerce sites. You can create scalable applications that rival industry leaders like Nike and Zalando by leveraging SSR, SSG, and automatic optimizations.&lt;br&gt;
Follow these five steps to set up your site and enhance it with security and performance best practices for a professional, user-friendly experience. For complex projects, consider partnering with an &lt;a href="https://www.lucentinnovation.com/pages/hire-reactjs-developers" rel="noopener noreferrer"&gt;Expert ReactJS developer&lt;/a&gt; to ensure scalability and maintenance. &lt;/p&gt;

</description>
      <category>ecommerce</category>
      <category>seofriendly</category>
      <category>react</category>
      <category>nextjs</category>
    </item>
    <item>
      <title>Building Accessible and Performant UI/UX with React JS</title>
      <dc:creator>Elias Garcia</dc:creator>
      <pubDate>Mon, 28 Apr 2025 06:42:53 +0000</pubDate>
      <link>https://dev.to/deep_raval_16fa6674dda823/building-accessible-and-performant-uiux-with-react-js-2g6h</link>
      <guid>https://dev.to/deep_raval_16fa6674dda823/building-accessible-and-performant-uiux-with-react-js-2g6h</guid>
      <description>&lt;p&gt;Creating dynamic, user-friendly interfaces requires React JS most of the time. To really improve UI/UX, though, developers need to put performance and accessibility (a11y) first. These steps depict practical techniques to build accessible, high-performing React apps that users admire.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Accessibility and Performance Matter
&lt;/h2&gt;

&lt;p&gt;In React JS applications, accessibility and performance have a direct impact on the app's overall success.&lt;/p&gt;

&lt;p&gt;Suppose accessibility and performance are not correctly optimized. In that case, it can lead to a poor user experience, higher bounce rates, and lower engagement, all of which negatively affect how search engines like Google evaluate the app.&lt;/p&gt;

&lt;p&gt;Moreover, React apps require careful handling of rendering strategies like Server-Side Rendering (SSR) or Static Site Generation (SSG) to ensure that content is easily crawlable by search engines. Without focusing on accessibility, performance, and proper rendering techniques, achieving higher search engine rankings becomes extremely difficult.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Crafting Accessible UI in React
&lt;/h2&gt;

&lt;p&gt;Accessibility ensures your app is inclusive. Here’s how to implement it in React: &lt;/p&gt;

&lt;h3&gt;
  
  
  Use Semantic HTML
&lt;/h3&gt;

&lt;p&gt;Leverage semantic elements like , , and  for better screen reader support. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;button aria-label="Close dialog"&amp;gt;X&amp;lt;/button&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Manage Focus
&lt;/h3&gt;

&lt;p&gt;Use useRef to control focus for keyboard navigation, especially in modals or forms.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useRef, useEffect } from 'react'; 

function Modal({ isOpen, onClose }) { 
  const buttonRef = useRef(null); 

  useEffect(() =&amp;gt; { 
    if (isOpen) buttonRef.current.focus(); 
  }, [isOpen]); 

  return ( 
    &amp;lt;div role="dialog" aria-modal="true"&amp;gt; 
      &amp;lt;button ref={buttonRef} onClick={onClose}&amp;gt;Close&amp;lt;/button&amp;gt; 
    &amp;lt;/div&amp;gt; 
  ); 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Leverage ARIA Attributes
&lt;/h3&gt;

&lt;p&gt;Add ARIA roles and states to enhance screen reader compatibility. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;div role="alert" aria-live="assertive"&amp;gt;Error: Invalid input&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Use Accessibility Libraries
&lt;/h3&gt;

&lt;p&gt;Libraries like &lt;code&gt;react-axe&lt;/code&gt; or &lt;code&gt;eslint-plugin-jsx-a11y&lt;/code&gt; help catch a11y issues during &lt;a href="https://www.lucentinnovation.com/services/reactjs-development" rel="noopener noreferrer"&gt;React JS development&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Optimizing Performance for Seamless UX
&lt;/h2&gt;

&lt;p&gt;A performant React app feels snappy and responsive. Try these techniques: &lt;/p&gt;

&lt;h3&gt;
  
  
  Minimize Re-renders with Memorization
&lt;/h3&gt;

&lt;p&gt;Use &lt;code&gt;React.memo&lt;/code&gt;, &lt;code&gt;useMemo&lt;/code&gt;, and &lt;code&gt;useCallback&lt;/code&gt; to prevent unnecessary renders.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const ExpensiveComponent = React.memo(({ data }) =&amp;gt; ( 
  &amp;lt;div&amp;gt;{data}&amp;lt;/div&amp;gt; 
)); 

function Parent() { 
  const memoizedValue = useMemo(() =&amp;gt; computeExpensiveValue(), []); 
  return &amp;lt;ExpensiveComponent data={memoizedValue} /&amp;gt;; 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Lazy Load Components
&lt;/h3&gt;

&lt;p&gt;Split your app with &lt;code&gt;React.lazy&lt;/code&gt; and Suspense to load components only when needed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const HeavyComponent = React.lazy(() =&amp;gt; import('./HeavyComponent')); 

function App() { 
  return ( 
    &amp;lt;Suspense fallback={&amp;lt;div&amp;gt;Loading...&amp;lt;/div&amp;gt;}&amp;gt; 
      &amp;lt;HeavyComponent /&amp;gt; 
    &amp;lt;/Suspense&amp;gt; 
  ); 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Optimize Images
&lt;/h3&gt;

&lt;p&gt;Use modern formats like WebP and libraries like &lt;code&gt;react-lazy-load-image-component&lt;/code&gt; for faster load times.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Testing Your UI/UX
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Accessibility Testing:&lt;/strong&gt; Use tools like Lighthouse or axe DevTools to audit your app.&lt;br&gt;
&lt;strong&gt;Performance Testing:&lt;/strong&gt; Profile with React DevTools or Chrome’s Performance tab.&lt;br&gt;
&lt;strong&gt;User Testing:&lt;/strong&gt; Gather feedback to ensure your UI/UX meets real-world needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Building accessible and performant UI/UX with React JS is both a necessity and an opportunity. By focusing on semantic HTML, ARIA, memoization, and lazy loading, you can create inclusive, fast, and engaging experiences. Start small, test often, and watch your app’s user satisfaction soar! &lt;/p&gt;

&lt;p&gt;Dive deeper with React’s official documentation or explore libraries like &lt;a href="https://react-spectrum.adobe.com/react-aria/index.html" rel="noopener noreferrer"&gt;react-aria&lt;/a&gt; for advanced accessibility features. &lt;/p&gt;

</description>
      <category>uidesign</category>
      <category>uxdesign</category>
      <category>react</category>
    </item>
    <item>
      <title>Key Factors to Consider While Installing ZooKeeper on Ubuntu</title>
      <dc:creator>Elias Garcia</dc:creator>
      <pubDate>Wed, 26 Mar 2025 09:57:49 +0000</pubDate>
      <link>https://dev.to/deep_raval_16fa6674dda823/key-factors-to-consider-while-installing-zookeeper-on-ubuntu-59co</link>
      <guid>https://dev.to/deep_raval_16fa6674dda823/key-factors-to-consider-while-installing-zookeeper-on-ubuntu-59co</guid>
      <description>&lt;p&gt;Apache ZooKeeper is a centralized service that maintains configuration information, names, and provides distributed synchronization and group services. If you're &lt;a href="https://www.lucentinnovation.com/blogs/technology-posts/a-step-by-step-guide-to-installing-zookeeper" rel="noopener noreferrer"&gt;installing ZooKeeper on Ubuntu&lt;/a&gt;, there are several important factors to ensure a smooth and secure setup. Let's break them down:&lt;/p&gt;

&lt;h2&gt;
  
  
  1. System Requirements and Compatibility
&lt;/h2&gt;

&lt;p&gt;Before installation, ensure your Ubuntu version is compatible with the ZooKeeper release. Most ZooKeeper versions work well with Ubuntu 18.04 or later, but it's always best to check the official documentation. Also, make sure your system has enough memory and disk space. ZooKeeper is lightweight but can grow significantly depending on usage.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Java Installation
&lt;/h2&gt;

&lt;p&gt;ZooKeeper is a Java-based application, so Java 8 or later must be installed. You can check your Java version using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;java -version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If not installed, use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install openjdk-11-jdk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ensure JAVA_HOME is correctly configured in your environment.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Dedicated User and Permissions
&lt;/h2&gt;

&lt;p&gt;For security purposes, it's recommended to create a dedicated user for ZooKeeper:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo useradd -m -s /bin/bash zookeeper
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Avoid running ZooKeeper as root. Also, ensure proper file and directory permissions are set for configuration and data directories.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Data Directory Setup
&lt;/h2&gt;

&lt;p&gt;ZooKeeper requires a directory to store its data &lt;code&gt;(dataDir)&lt;/code&gt; and transaction logs. These should be stored on a non-volatile, high-speed disk to improve performance and durability. You can specify this directory in the &lt;code&gt;zoo.cfg&lt;/code&gt; configuration file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dataDir=/var/lib/zookeeper
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Configuration File (&lt;code&gt;zoo.cfg&lt;/code&gt;)
The ZooKeeper configuration file needs to be customized for your environment:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;tickTime&lt;/code&gt;: Basic time unit (ms) used by ZooKeeper.&lt;br&gt;
&lt;code&gt;dataDir&lt;/code&gt;: Path to the ZooKeeper data directory.&lt;br&gt;
&lt;code&gt;clientPort&lt;/code&gt;: Port where ZooKeeper listens for client connections (default: 2181).&lt;br&gt;
&lt;code&gt;initLimit&lt;/code&gt; and &lt;code&gt;syncLimit&lt;/code&gt;: Parameters for leader election and synchronization in clustered setups.&lt;br&gt;
If you're setting up a multi-node cluster, define each server like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server.1=zoo1:2888:3888
server.2=zoo2:2888:3888
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  6. Networking and Firewall
&lt;/h2&gt;

&lt;p&gt;Ensure the necessary ports (usually 2181, 2888, and 3888) are open and not blocked by a firewall. If you're working in a cloud environment (like AWS or Azure), update the security group or network rules accordingly.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Running ZooKeeper as a Service
&lt;/h2&gt;

&lt;p&gt;Instead of starting ZooKeeper manually, it's best to set it up as a system service. This ensures it starts on boot and can be monitored easily:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo nano /etc/systemd/system/zookeeper.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add service details pointing to your ZooKeeper installation and enable it using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl enable zookeeper
sudo systemctl start zookeeper
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  8. Monitoring and Logging
&lt;/h2&gt;

&lt;p&gt;ZooKeeper logs important events to files that can be found in the &lt;code&gt;logs/&lt;/code&gt; directory. Make sure log rotation is enabled and monitor performance using tools like &lt;code&gt;zkCli.sh&lt;/code&gt;, the mntr command, or external services like Prometheus exporters.&lt;/p&gt;

&lt;h2&gt;
  
  
  9. Security and Access Control
&lt;/h2&gt;

&lt;p&gt;ZooKeeper offers authentication and ACLs (Access Control Lists) for node access. Configure &lt;code&gt;authProvider.1=org.apache.zookeeper.server.auth.SASLAuthenticationProvider&lt;/code&gt; in the config file if needed. Also, avoid exposing ZooKeeper to the public internet.&lt;/p&gt;

&lt;h2&gt;
  
  
  10. Backup and Recovery Strategy
&lt;/h2&gt;

&lt;p&gt;Always plan for disaster recovery:&lt;/p&gt;

&lt;p&gt;Take regular snapshots of the data directory.&lt;br&gt;
Monitor for latency or increased size in transaction logs.&lt;br&gt;
Use ZooKeeper's built-in backup options or schedule periodic filesystem-level backups.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Installing ZooKeeper on Ubuntu isn't just about running a few commands — it's about ensuring a stable, secure, and scalable setup. By considering these factors, you'll lay the foundation for a robust distributed system that can support your applications with high availability and consistency.&lt;/p&gt;

</description>
      <category>zookeeper</category>
      <category>ubuntu</category>
      <category>installation</category>
    </item>
  </channel>
</rss>
