Naan Mudhalavan Frontend Development Session - 8

Naan Mudhalavan Frontend Development Session - 8

TLDR;

This session covers React props, states, hooks (useState and useEffect), Bootstrap integration, and conditional rendering. It explains how to pass data between components using props, manage component state with useState, and perform side effects with useEffect. The session also demonstrates how to integrate Bootstrap for styling and use conditional rendering to toggle themes.

  • Creating React App and Components
  • Passing Data with Props
  • Managing State with useState
  • Integrating Bootstrap and Conditional Rendering with useEffect

Creating a React App and Components [44:37]

The session begins with creating a new React application using npm create vite@latest and naming the project "nclient". The React framework and JavaScript are selected during the setup. After navigating into the project directory (cd nclient) and installing dependencies (npm install), the development server is started with npm run dev. A "components" folder is created inside the "src" folder to house React components. A new component named "myComponent.jsx" is created. The presenter recommends installing the "ES7 React Redux GraphQL React Native" extension for VS Code to enable useful React snippets like RFC for creating functional components.

Passing Data with Props [52:24]

The session explains how to pass data from one component to another using props. In "app.jsx", a property called "name" is assigned the value "Nelaturi Aparna" and passed to the "myComponent" component. Inside "myComponent.jsx", the passed prop is accessed via the props object. The value of props.name is then logged to the console and displayed within the component. The presenter demonstrates that React components can be used multiple times with different prop values, illustrating how the "myComponent" is rendered three times with different names passed as props. Props are unidirectional, meaning data flows from parent to child components only. The session expands on this by passing a JavaScript object as a prop called "info", containing "name" and "company" properties. The component then accesses and displays these properties.

Managing State with useState [1:08:59]

The session introduces React states using the useState hook. A "counter" component is created with increment and decrement buttons. The useState hook is used to manage a count variable, initialised to zero. The useState hook returns an array containing the current state value (count) and a function to update it (setCount). When the increment button is clicked, the setCount function is called to update the count, triggering a re-render of the component. The updated count is then displayed in the component. The presenter explains that React doesn't automatically re-render the HTML when a variable changes; useState is needed to trigger these updates.

Integrating Bootstrap and Conditional Rendering with useEffect [1:34:25]

The session demonstrates how to integrate Bootstrap into a React application for styling. The Bootstrap CSS and JavaScript links are added to the "index.html" file. An accordion component is then copied from the Bootstrap documentation and integrated into the "app.jsx" file. The session then covers conditional rendering to change the theme of the page using a toggle button. The useState hook is used to manage a style object, which is initially set to a dark theme. When the toggle button is clicked, the style object is updated to a light theme, and vice versa. The presenter uses both if/else statements and ternary operators to implement the conditional rendering. Finally, the useEffect hook is introduced to perform side effects, such as fetching data when the component mounts or when a state variable changes. The presenter explains that useEffect takes two arguments: a callback function and a dependency array. The callback function is executed when the component mounts and whenever any of the dependencies change.

Watch the Video

Date: 8/30/2025 Source: www.youtube.com
Share

Stay Informed with Quality Articles

Discover curated summaries and insights from across the web. Save time while staying informed.

© 2024 BriefRead