Loading...
A community-driven platform where students, developers, and tech enthusiasts share ideas, publish projects, discuss innovations, and explore the future of AI and modern technology.
Introduction In React, components are like Lego blocks โ you can build small pieces and combine them into bigger structures. But how do these blocks talk to each other ? Thatโs where props come in. Props (short for properties ) let you pass data from one component to another, making your app dynamic and reusable. ๐ What are Props? Definition: Props are inputs to components. Analogy: Think of props like arguments you pass into a function. Key Idea: Props make components flexible โ the same component can display different content depending on the props it receives. ๐งโ๐ป Step 1: Create a Child Component Letโs make a simple Greeting component that accepts a name prop. import React from "react"; function Greeting(props) { return <h2>Hello, {props.name}! ๐</h2>; } export default Greeting; ๐งโ๐ป Step 2: Use Props in the Parent Component Now, letโs use Greeting inside App.js : import React from "react"; import Greeting from "./Greeting"; function App() { return ( <div style={{ textAlign: "center", marginTop: "50px" }}> <h1>Welcome to My React App</h1> <Greeting name="Alice" /> <Greeting name="Bob" /> <Greeting name="Charlie" /> </div> ); } export default App; ๐ Output: Welcome to My React App Hello, Alice! ๐ Hello, Bob! ๐ Hello, Charlie! ๐ ๐จ Whatโs Happening Here? The Greeting component is reusable . Each time we call <Greeting name="..." /> , we pass a different prop. React renders the component with the given data. โ Conclusion Props are the glue that connects React components. They allow you to pass data down the component tree, making your app modular and flexible. ๐ก Student Challenge: Create a Profile component that takes props like name , age , and city , then display them in a styled card.
Jonny Peterson
13 May 2026
IntroductionReact is one of the most popular JavaScript libraries for building user interfaces. Itโs powerful, flexible, and widely used in modern web development. In this post, weโll start with the basics: creating a simple app that displays a message and lets you click a button to increase a counter.Key Concepts Youโll LearnComponents: The building blocks of React apps.JSX: A syntax that looks like HTML but works inside JavaScript.State: How React remembers values between renders.Events: Handling user actions like button clicks.Step 1: Setting UpIf you donโt already have a React project, you can create one using:bashnpx create-react-app my-first-app cd my-first-app npm start This will start a development server and open your app in the browser.Step 2: Create Your First ComponentOpen src/App.js and replace the content with:import React, { useState } from "react"; function App() { // Declare a state variable called "count" const [count, setCount] = useState(0); return ( <div style={{ textAlign: "center", marginTop: "50px" }}> <h1>Hello, React World! ๐</h1> <p>You clicked {count} times</p> <button onClick={() => setCount(count + 1)}> Click Me </button> </div> ); } export default App; Whatโs Happening Here?useState(0) โ Creates a state variable count starting at 0.setCount(count + 1) โ Updates the state when the button is clicked.Every time state changes, React re-renders the component with the new value.Suggested VisualsA screenshot of the app showing the counter.A diagram of the React component lifecycle: Render โ User Click โ State Update โ Re-render.ConclusionYouโve just built your first interactive React app! ๐ This simple counter demonstrates the core idea of React: UI updates automatically when state changes.๐ก Student Challenge: Add another button that decreases the counter, and a reset button that sets it back to zero.