SMELLING THE REACT: MY JOURNEY INTO THE WORLD OF REACT.JS

SMELLING THE REACT: MY JOURNEY INTO THE WORLD OF REACT.JS

React.js is known for making web development simpler and more efficient, but there’s more to it than just building user interfaces. In my recent journey, I’ve explored how React simplifies UI creation by breaking it down into components while introducing tools and best practices to streamline development.

Why You Should Learn React


React isn't just a library—it’s a gateway to building modern, fast, and scalable web applications. Unlike frameworks that try to provide everything, React focuses on user interface development. You don’t need to know everything to get started with React, which makes it an ideal choice for developers of all levels.


Key Features of React:

Component-Based Architecture: React allows you to break down your UI into small, reusable components, making development easier and more modular.

Fast Refresh: This feature enables real-time updates when modifying components, without losing the application’s state.

Third-Party Solutions: With its active community, many of the challenges developers face have already been solved through third-party packages and open-source projects.


React's Versatility

React is not limited to websites. You can use it to build various types of applications, such as:

  • Websites: Content-focused platforms like blogs and portfolios.
  • Web Applications: For more interactive platforms like e-commerce or social media.
  • Progressive Web Apps (PWAs): Apps that offer offline support and a native-like experience.
  • React Native: For building mobile applications on iOS and Android using the same React principles.


Setting Up the Environment

Setting up React might seem complex at first, but the process can be straightforward with the right tools:

  1. VS Code as the code editor.
  2. Node.js and npm: Installing Node.js automatically includes npm, the default package manager for JavaScript, essential for handling dependencies in React projects.
  3. Babel: A JavaScript compiler that helps convert JSX (a special syntax used by React) into plain JavaScript that browsers can understand. I initially used Babel’s online tool to compile JSX, but later integrated it directly into my development setup using npm.


Creating a Basic React Application

Here’s the step-by-step breakdown of creating a React app manually, which helped me grasp its core concepts:

  1. Initialize the project: Running npm init -y creates the basic structure with a package.json file.
  2. Install Babel: Adding Babel to VS Code ensures JSX gets converted into browser-friendly JavaScript.
  3. Create the structure: Inside the src folder, I created an app.js file where all JSX code resides. I linked this to the index.html file in the public folder, using a CDN to load React and ReactDOM.
  4. Write JSX and Compile: Writing basic JSX and running npx babel to compile the code and check the output in the browser using Live Server.

  • This hands-on setup allowed me to understand the core of how React works behind the scenes.


Key Concepts I Learned So Far:

  • JSX (JavaScript XML): JSX is not just HTML within JavaScript—it needs to be compiled. Using Babel, I converted JSX into regular JavaScript to be processed by the browser. A key learning here is that browsers don't understand JSX natively, and this compilation step is essential.
  • Dynamic Components: React components can be rendered dynamically using variables, arrays, and conditional rendering.
  • I explored how to: Create student details using variables and arrays.
  • I explored how to: Render components conditionally based on data, such as showing grades or hiding email fields depending on whether the data exists.
  • Arrow Functions: Using arrow functions in React was a game-changer. They inherit the this context from their parent, which simplifies the handling of objects, especially in complex functions like mapping through arrays.


Efficiency Through Automation

Manually running Babel to compile the JSX each time I made a change was repetitive. I switched to using --watch mode with Babel, allowing real-time updates whenever I edited the code:

npx babel src/app.js --out-file=public/js/app.js --presets=@babel/env,@babel/react --watch        

This ensured that my React app would refresh automatically with every code change, making development smoother.


Rendering Dynamic Data and Arrays

I also learned how to handle dynamic data in React, such as rendering lists of student details. The key prop is crucial here, as it helps React track which items have changed, improving the efficiency of rendering lists:

students.map((student) => <div key={student.id}>{student.name}</div>);        

React fragments were another interesting concept. Although fragments help prevent unnecessary DOM elements, in cases where unique keys are needed, using a <div> instead of a fragment can be more practical.

Moving Forward

My initial experience with React has been rewarding, and I am excited to continue exploring advanced topics like state management, hooks, and API integration. The beauty of React lies in its simplicity and efficiency. As I progress, I aim to build more complex applications and contribute to open-source projects in the React ecosystem.

Radika Dilanka

Web Consultant | React Instructor (200+ Developers Taught) | MERN-Stack Developer | React, Node.js

6 个月

way to go ??

VIGNESH B

KINGSTON ENGINEERING COLLEGE

6 个月

Interesting

Gayandi Panditharathna

Electronics and Telecommunication Engineering Graduate | CCNA | Software Engineer | FullStack Developer | QA Enthusiast | PHP | Laravel | JavaScript | JQuery | HTML | CSS | SQL | Java

6 个月

Very informative !

要查看或添加评论,请登录

Shashika Jayathilaka的更多文章

社区洞察

其他会员也浏览了