<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Yusuf Efe on Medium]]></title>
        <description><![CDATA[Stories by Yusuf Efe on Medium]]></description>
        <link>https://medium.com/@yusufefe417?source=rss-622544ed7a5d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Yusuf Efe on Medium</title>
            <link>https://medium.com/@yusufefe417?source=rss-622544ed7a5d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 04:21:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yusufefe417/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[React, React Hooks, React Components and React DOM [EN]]]></title>
            <link>https://medium.com/@yusufefe417/react-react-hooks-react-components-and-react-dom-en-9d2bd262129b?source=rss-622544ed7a5d------2</link>
            <guid isPermaLink="false">https://medium.com/p/9d2bd262129b</guid>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-components]]></category>
            <category><![CDATA[react-dom]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Yusuf Efe]]></dc:creator>
            <pubDate>Sat, 01 Feb 2025 12:18:47 GMT</pubDate>
            <atom:updated>2025-02-01T12:18:47.087Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is React? Why is it Used?</h3><p>In today’s web development world, user experience and speed are prioritized. At this point, React stands out as one of the most popular libraries for developing modern user interfaces. Developed by Facebook and released as open-source in 2013, React enables the creation of scalable, reusable, and easily manageable interfaces thanks to its component-based architecture.</p><p>The main purpose of React is to make application interfaces fast, efficient, and modular. To achieve this, it utilizes powerful features such as components and the virtual DOM. Compared to traditional DOM manipulations, the virtual DOM significantly improves performance by identifying and updating only the necessary elements.</p><p>Additionally, the concept of Hooks in React enhances the capabilities of functional components, allowing state management and handling side effects more efficiently.</p><h3>2. React Components</h3><p>One of the most important building blocks of React is components. Components are structures that divide a React application into independent and reusable small parts, making it more manageable. This speeds up the development process and improves code readability.</p><p>React components are small, independent building blocks that combine HTML, CSS, and JavaScript. Repetitive elements on a web page, such as buttons, forms, cards, or navigation bars, can be defined as components.</p><h4>2.1 What is the Concept of Components in React, and Why is it Used?</h4><p>Components are used to break down large and complex user interfaces into smaller, manageable parts. When using traditional HTML and JavaScript, code complexity becomes inevitable in large projects. However, React components solve this issue by treating each part as an independent module.</p><p>The key advantages of components include:</p><ul><li><strong>Reusability:</strong> A component can be used multiple times in different places. For example, you can create a “Button” component and use it on different pages.</li><li><strong>Independence:</strong> Components work on their own and are independent of each other. Changes made in one component do not affect others.</li><li><strong>Ease of Maintenance:</strong> Thanks to their small and modular structure, identifying and fixing errors becomes much easier.</li><li><strong>Cleaner and More Organized Code:</strong> Breaking code into parts improves readability and speeds up development.</li></ul><h4>2.2 Types of Components in React</h4><p>React components are generally divided into two main types: <strong>Functional Components</strong> and <strong>Class Components</strong>.</p><p><strong>2.2.1 Functional Components</strong></p><p>Functional components are the most commonly used component type today. They are simple, efficient, and recommended by the React team. With React Hooks, many features that were previously available only in class components can now be used in functional components.</p><p>A functional component is defined like a JavaScript function and returns JSX to create the user interface:</p><pre>function Welcome(props) {<br>  return &lt;h1&gt;Hello, {props.name}!&lt;/h1&gt;;<br>}<br><br>export default Welcome;</pre><p>This component can be used in a page as follows:</p><pre>&lt;Welcome name=&quot;Ahmet&quot; /&gt;</pre><p>Here, a prop (property) named <strong>name</strong> is used. Props allow passing dynamic data to components.</p><p><strong>2.2.2 Class Components</strong></p><p>Class components were widely used in earlier versions of React and are created using ES6 class syntax. However, after the introduction of Hooks in React 16.8, the need for class components has decreased.</p><p>Example of a class component:</p><pre>import React, { Component } from &quot;react&quot;;<br><br>class Welcome extends Component {<br>  render() {<br>    return &lt;h1&gt;Hello, {this.props.name}!&lt;/h1&gt;;<br>  }<br>}<br><br>export default Welcome;</pre><p>Compared to functional components, class components are more verbose and complex. Additionally, managing the this keyword can lead to errors.</p><h4>2.3 Using Props and State</h4><p>React components rely on two main data management tools: <strong>Props</strong> and <strong>State</strong>.</p><p><strong>2.3.1 What is Props?</strong></p><p>Props (short for “properties”) are data passed from a parent component to a child component. They are read-only and cannot be modified within the component. Props work similarly to attributes in HTML elements.</p><p>Example usage:</p><pre>function UserCard(props) {<br>  return (<br>    &lt;div&gt;<br>      &lt;h2&gt;{props.name}&lt;/h2&gt;<br>      &lt;p&gt;Age: {props.age}&lt;/p&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>// Usage:<br>&lt;UserCard name=&quot;Ahmet&quot; age={25} /&gt;</pre><p>Here, name and age are passed as props to the UserCard component. Since props are <strong>read-only</strong>, they cannot be modified inside the component.</p><p><strong>2.3.2 What is State?</strong></p><p>State is used to store data that can change within a component. It updates when the user interacts with the interface or when an event occurs.</p><p>In functional components, state is managed using the useState Hook:</p><pre>import { useState } from &quot;react&quot;;<br><br>function Counter() {<br>  const [count, setCount] = useState(0);<br><br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;Counter: {count}&lt;/p&gt;<br>      &lt;button onClick={() =&gt; setCount(count + 1)}&gt;Increase&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default Counter;</pre><p>Here, useState(0) initializes a state variable with a value of 0, and the setCount function updates it.</p><h4>2.4 Data Flow Between Components</h4><p>In a React application, components typically follow a parent-child relationship. However, managing data flow can sometimes be challenging.</p><p><strong>2.4.1 Props Drilling Issue</strong></p><p>When data needs to be passed to a deeply nested component, it must be forwarded through multiple intermediary components. This is known as <strong>Props Drilling</strong>, and it can make the code harder to read and maintain.</p><p>To solve this issue, the following methods can be used:</p><ul><li><strong>Context API</strong></li><li><strong>State Management Libraries</strong> (e.g., Redux, Zustand)</li></ul><p>For example, using the Context API can prevent props drilling:</p><pre>import { createContext, useContext } from &quot;react&quot;;<br><br>const UserContext = createContext();<br><br>function Parent() {<br>  return (<br>    &lt;UserContext.Provider value=&quot;Ahmet&quot;&gt;<br>      &lt;Child /&gt;<br>    &lt;/UserContext.Provider&gt;<br>  );<br>}<br><br>function Child() {<br>  const user = useContext(UserContext);<br>  return &lt;h1&gt;Hello, {user}!&lt;/h1&gt;;<br>}</pre><p>This allows the user value to be accessed directly inside the Child component.</p><p>React components are essential tools for making user interfaces more <strong>modular, scalable, and manageable</strong>. Understanding the differences between functional and class components, knowing how to use props and state, and managing data flow between components are <strong>crucial</strong> for building robust React applications.</p><h3>3. React Hooks</h3><p>With the release of React 16.8, Hooks were introduced to make functional components more powerful. Previously, features like state management and lifecycle methods were only available in class components. Thanks to Hooks, these features can now be used within functional components as well.</p><h3>Advantages of Using Hooks:</h3><ul><li>More functionality with less code</li><li>Improved code readability and maintainability</li><li>No need to deal with this in class components</li><li>Avoiding code duplication by creating cleaner and more modular structures</li></ul><h4>3.1 What Are React Hooks?</h4><p>Hooks are special JavaScript functions that allow functional components to use state and lifecycle methods.</p><p><strong>Rules for Using Hooks:</strong></p><ul><li>Hooks can only be called inside functional components or custom Hooks.</li><li>They cannot be used inside loops, conditions, or nested functions.</li></ul><p>Example usage:</p><pre>const [count, setCount] = useState(0);</pre><p>Now, let’s explore the most commonly used React Hooks.</p><h4>3.2 useState: Managing State</h4><p>useState is used to store variables inside a component and re-render it when the state changes.</p><p><strong>Example: A Counter Component</strong></p><pre>import { useState } from &quot;react&quot;;<br><br>function Counter() {<br>  const [count, setCount] = useState(0); // Define the count state.<br><br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;Counter: {count}&lt;/p&gt;<br>      &lt;button onClick={() =&gt; setCount(count + 1)}&gt;Increase&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default Counter;</pre><ul><li>useState(0): Initializes the count state with a value of 0.</li><li>setCount(count + 1): Updates the state and triggers a re-render.</li></ul><h4>3.3 useEffect: Managing Side Effects</h4><p>useEffect is used to handle side effects such as:</p><ul><li>Making API requests</li><li>Manipulating the DOM</li><li>Running code when a component mounts</li></ul><p><strong>Example: Logging a message when the component mounts</strong></p><pre>import { useState, useEffect } from &quot;react&quot;;<br><br>function App() {<br>  const [count, setCount] = useState(0);<br><br>  useEffect(() =&gt; {<br>    console.log(&quot;Component mounted!&quot;);<br>  }, []); // The empty dependency array ensures it runs only once.<br><br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;Counter: {count}&lt;/p&gt;<br>      &lt;button onClick={() =&gt; setCount(count + 1)}&gt;Increase&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><h4><strong>Dependency Array (</strong><strong>[])</strong></h4><ul><li>If empty ([]), useEffect runs only once when the component mounts.</li><li>If a variable is included ([count]), it runs whenever count changes.</li><li>If omitted, useEffect runs after every render (which can lead to performance issues).</li></ul><p>Example where it runs when count changes:</p><pre>useEffect(() =&gt; {<br>  console.log(`Counter updated: ${count}`);<br>}, [count]);</pre><h4>3.4 useContext: Managing Global State</h4><p>useContext simplifies state sharing between components and helps avoid <strong>props drilling</strong> (passing props through multiple components).</p><p><strong>Example: Sharing a username globally</strong></p><pre>import { createContext, useContext } from &quot;react&quot;;<br><br>const UserContext = createContext();<br><br>function Parent() {<br>  return (<br>    &lt;UserContext.Provider value=&quot;John&quot;&gt;<br>      &lt;Child /&gt;<br>    &lt;/UserContext.Provider&gt;<br>  );<br>}<br><br>function Child() {<br>  const user = useContext(UserContext);<br>  return &lt;h1&gt;Hello, {user}!&lt;/h1&gt;;<br>}</pre><p>Now, the user value can be accessed directly in the Child component without passing it as a prop.</p><h4>3.5 useReducer vs useState: When to Use Which?</h4><ul><li>Use useState for simple state updates:</li></ul><pre>const [count, setCount] = useState(0);</pre><ul><li>Use useReducer for complex state logic.</li></ul><p><strong>Example: A Counter Using </strong><strong>useReducer</strong></p><pre>import { useReducer } from &quot;react&quot;;<br><br>function reducer(state, action) {<br>  switch (action.type) {<br>    case &quot;increment&quot;:<br>      return { count: state.count + 1 };<br>    case &quot;decrement&quot;:<br>      return { count: state.count - 1 };<br>    default:<br>      return state;<br>  }<br>}<br><br>function Counter() {<br>  const [state, dispatch] = useReducer(reducer, { count: 0 });<br><br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;Counter: {state.count}&lt;/p&gt;<br>      &lt;button onClick={() =&gt; dispatch({ type: &quot;increment&quot; })}&gt;Increase&lt;/button&gt;<br>      &lt;button onClick={() =&gt; dispatch({ type: &quot;decrement&quot; })}&gt;Decrease&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p><strong>When to Use </strong><strong>useReducer?</strong></p><ul><li>If managing complex state logic</li><li>When different actions modify the state</li><li>When handling multiple state values</li></ul><h4>3.6 Custom Hooks: Creating Reusable Logic</h4><p>If you need to reuse logic across multiple components, <strong>custom Hooks</strong> can help eliminate redundancy.</p><p><strong>Example: A Hook to Track Window Width</strong></p><pre>import { useState, useEffect } from &quot;react&quot;;<br><br>function useWindowWidth() {<br>  const [width, setWidth] = useState(window.innerWidth);<br><br>  useEffect(() =&gt; {<br>    const handleResize = () =&gt; setWidth(window.innerWidth);<br>    window.addEventListener(&quot;resize&quot;, handleResize);<br><br>    return () =&gt; {<br>      window.removeEventListener(&quot;resize&quot;, handleResize);<br>    };<br>  }, []);<br><br>  return width;<br>}<br><br>function App() {<br>  const width = useWindowWidth();<br><br>  return &lt;h1&gt;Window width: {width}px&lt;/h1&gt;;<br>}</pre><p>Now, we can use the useWindowWidth Hook in any component without duplicating code.</p><p>React Hooks make modern React applications <strong>more modular, readable, and maintainable</strong>. Understanding essential Hooks like useState, useEffect, useContext, and useReducer is <strong>crucial</strong> for building advanced React applications.</p><h3>4. React DOM (Document Object Model) Management</h3><p>One of React’s strongest features is its optimized DOM management, which allows developers to efficiently create UI components. Unlike traditional JavaScript and jQuery, where DOM manipulation is done directly, React enhances this process with the Virtual DOM, making it significantly more efficient.</p><h3>4.1 Difference Between DOM and Virtual DOM</h3><p>Before diving deeper, it’s important to understand the difference between the traditional DOM and the Virtual DOM.</p><p>🔴 <strong>Traditional DOM:</strong></p><ul><li>Represents the tree structure of an HTML document, where each element is a node.</li><li>Can be directly manipulated using JavaScript.</li><li>Performance issues arise since changes trigger reprocessing of large portions of the page.</li></ul><p>🟢 <strong>Virtual DOM (V-DOM):</strong></p><ul><li>A lightweight copy of the actual DOM stored in memory.</li><li>Identical to the real DOM, but changes are not directly applied.</li><li>Uses a diffing algorithm to detect changes and updates only the necessary parts.</li><li>Enhances performance by preventing unnecessary re-rendering.</li></ul><h4>How Virtual DOM Works:</h4><ol><li>A new Virtual DOM is created when setState is called.</li><li>React compares the new and old Virtual DOM (diffing process).</li><li>Only modified parts are applied to the actual DOM.</li></ol><p>This mechanism significantly improves performance by minimizing DOM operations.</p><h4>4.2 DOM Manipulation in React</h4><p>Unlike traditional JavaScript, React abstracts DOM manipulations using the Virtual DOM. However, in some cases, direct DOM access may be necessary.</p><p><strong>Example: Traditional JavaScript DOM Update</strong></p><pre>&lt;button onclick=&quot;document.getElementById(&#39;text&#39;).innerHTML = &#39;Hello!&#39;&quot;&gt;&lt;br&gt;  Update<br>&lt;/button&gt;<br>&lt;p id=&quot;text&quot;&gt;Hello, world!&lt;/p&gt;</pre><p><strong>Same Functionality in React (Optimized)</strong></p><pre>import { useState } from &quot;react&quot;;<br><br>function App() {<br>  const [text, setText] = useState(&quot;Hello, world!&quot;);<br><br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;{text}&lt;/p&gt;<br>      &lt;button onClick={() =&gt; setText(&quot;Hello!&quot;)}&gt;Update&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><h4>Why React is More Efficient?</h4><ul><li>The Virtual DOM optimizes updates.</li><li>Only changed elements are updated instead of the entire page.</li><li>React’s internal mechanisms prevent unnecessary re-renders.</li></ul><h4>4.3 Avoiding Extra DOM Elements with React.Fragment</h4><p>React components typically return a single root element. However, using unnecessary &lt;div&gt; wrappers can clutter the DOM.</p><p><strong>Example: Unnecessary </strong><strong>&lt;div&gt;</strong></p><pre>function List() {<br>  return (<br>    &lt;div&gt; {/* Unnecessary wrapper */}<br>      &lt;h1&gt;Title&lt;/h1&gt;<br>      &lt;p&gt;This is a paragraph.&lt;/p&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p><strong>Solution: Using </strong><strong>React.Fragment (</strong><strong>&lt;&gt; &lt;/&gt;) to Avoid Extra </strong><strong>&lt;div&gt;</strong></p><pre>function List() {<br>  return (<br>    &lt;&gt;<br>      &lt;h1&gt;Title&lt;/h1&gt;<br>      &lt;p&gt;This is a paragraph.&lt;/p&gt;<br>    &lt;/&gt;<br>  );<br>}</pre><ul><li>Leads to a cleaner and more efficient DOM.</li><li>Avoids unnecessary HTML elements.</li></ul><h4>4.4 Direct DOM Access with useRef</h4><p>In some cases, direct DOM access is required (e.g., focusing an input field). For such cases, useRef is used.</p><p><strong>Example: Automatically Focusing an Input Field</strong></p><pre>import { useRef, useEffect } from &quot;react&quot;;<br><br>function InputFocus() {<br>  const inputRef = useRef(null);<br><br>  useEffect(() =&gt; {<br>    inputRef.current.focus(); // Auto-focus on mount<br>  }, []);<br><br>  return &lt;input ref={inputRef} placeholder=&quot;Type here...&quot; /&gt;;<br>}<br><br>export default InputFocus;</pre><p><strong>Common Use Cases for </strong><strong>useRef:</strong></p><ul><li>Accessing DOM elements directly (focus, scroll, etc.).</li><li>Storing mutable values without triggering re-renders.</li><li>Keeping track of previous values of a state.</li></ul><h4>4.5 Rendering Outside of DOM Hierarchy with React Portals</h4><p>Sometimes, rendering React components outside the current DOM hierarchy is necessary (e.g., modals, tooltips, dropdowns). React Portals facilitate this.</p><p><strong>Example: Creating a Modal Component</strong></p><p>Add a portal container in index.html:</p><pre>&lt;div id=&quot;modal-root&quot;&gt;&lt;/div&gt;</pre><p><strong>Implementing React Portal:</strong></p><pre>import { useState } from &quot;react&quot;;<br>import ReactDOM from &quot;react-dom&quot;;<br><br>function Modal({ children }) {<br>  return ReactDOM.createPortal(<br>    &lt;div className=&quot;modal&quot;&gt;{children}&lt;/div&gt;,<br>    document.getElementById(&quot;modal-root&quot;)<br>  );<br>}<br><br>function App() {<br>  const [showModal, setShowModal] = useState(false);<br><br>  return (<br>    &lt;div&gt;<br>      &lt;button onClick={() =&gt; setShowModal(true)}&gt;Open Modal&lt;/button&gt;<br>      {showModal &amp;&amp; (<br>        &lt;Modal&gt;<br>          &lt;h2&gt;This is a modal!&lt;/h2&gt;<br>          &lt;button onClick={() =&gt; setShowModal(false)}&gt;Close&lt;/button&gt;<br>        &lt;/Modal&gt;<br>      )}<br>    &lt;/div&gt;<br>  );<br>}</pre><h4>Advantages of React Portals:</h4><ul><li>Allows rendering outside of the main DOM tree.</li><li>Useful for modal windows, tooltips, and dropdowns.</li><li>Avoids CSS issues with z-index, overflow, etc.</li></ul><h4>Summary and Final Thoughts</h4><p>React’s DOM management is crucial for performance and efficiency:</p><ul><li><strong>Virtual DOM</strong> outperforms traditional DOM by reducing unnecessary updates.</li><li><strong>React.Fragment</strong> eliminates extra wrapper elements.</li><li><strong>useRef</strong> enables direct DOM manipulation when needed.</li><li><strong>React Portals</strong> facilitate rendering elements outside the main DOM hierarchy.</li></ul><h4>Key Takeaways:</h4><ul><li>React Hooks simplify state and side effect management.</li><li>Component-based architecture ensures modular and reusable UI elements.</li><li>Virtual DOM optimizes updates and enhances performance.</li><li>React provides a fast, scalable, and flexible solution for modern web applications.</li></ul><p>With these principles, you can build highly efficient React applications with optimal DOM management.</p><p>GitHub — <a href="https://github.com/YusufEfe058">YusufEfe058</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9d2bd262129b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React, React Hooks, React Components ve React DOM [TR]]]></title>
            <link>https://medium.com/@yusufefe417/react-react-hooks-react-components-ve-react-dom-tr-2c4634d66d17?source=rss-622544ed7a5d------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c4634d66d17</guid>
            <category><![CDATA[react-components]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-dom]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[react-hook]]></category>
            <dc:creator><![CDATA[Yusuf Efe]]></dc:creator>
            <pubDate>Wed, 29 Jan 2025 11:07:16 GMT</pubDate>
            <atom:updated>2025-02-12T10:10:08.114Z</atom:updated>
            <content:encoded><![CDATA[<h3>1. React Nedir? Neden Kullanılır?</h3><p>Günümüzde web geliştirme dünyasında kullanıcı deneyimi ve hız ön planda tutulmaktadır. Bu noktada, React modern arayüzler geliştirmek için en popüler kütüphanelerden biri olarak öne çıkmaktadır. Facebook tarafından geliştirilen ve 2013 yılında açık kaynak olarak yayımlanan React, bileşen tabanlı mimarisi sayesinde ölçeklenebilir, yeniden kullanılabilir ve yönetimi kolay arayüzler oluşturmayı sağlar.</p><p>React’in temel amacı, uygulama arayüzünü hızlı, verimli ve modüler hale getirmektir. Bunu sağlamak için bileşenler (components) ve sanal DOM (virtual DOM) gibi güçlü özellikleri kullanır. Geleneksel Dom manipülasyonlarına kıyasla sanal DOM, güncellenmesi gereken öğeleri belirleyerek performansı önemli ölçüde artırır.</p><p>Ayrıca, React ile birlikte gelen Hooks kavramı, fonksiyonel bileşenlerin daha güçlü hale gelmesini sağlayarak state ve yan etkileri yönetmeye olanak tanır.</p><h3>2. React Components (Bileşenler)</h3><p>React’in en önemli yapı taşlarından biri bileşenlerdir (components). Bir React uygulamasını, birbirinden bağımsız ve tekrar kullanılabilir küçük parçalara bölerek yönetilebilir hale getiren yapılar bileşenlerdir. Bu, hem geliştirme sürecini hızlandırır hem de kodun okunabilirliğini kolaylaştırır.</p><p>React bileşenleri, HTML, CSS ve JavaScript’in bir araya getirilerek oluşturduğu küçük, bağımsız yapı taşlarıdır. Bir web sayfasında, buton, form, kart veya navigasyon çubuğu gibi tekrar eden öğeler bileşen olarak tanımlanabilir.</p><h4>2.1 React’te Bileşen Kavramı: Nedir ve Neden Kullanılır?</h4><p>Bileşenler, büyük ve karmaşık kullanıcı arayüzlerini küçük ve yönetilebilir parçalara bölmek için kullanılır. Geleneksel HTML ve JavaScript kullanıldığında, büyük projelerde kod karmaşası kaçınılmazdır. Ancak React bileşenleri, her parçayı bağımsız bir modül gibi ele alarak bu sorunu çözer. Bileşenlerin en büyük avantajları şunlardır:</p><ul><li><strong>Yeniden Kullanılabilirlik: </strong>Bir bileşeni farklı yerlerde tekrar tekrar kullanabilirsiniz. Örneğin, bir “Button” bileşeni oluşturup farklı sayfalarda çağırabilirsiniz.</li><li><strong>Bağımsızlık:</strong> Bileşenler kendi içlerinde çalışır ve birbirlerinden bağımsızdır. Bir bileşende yapılan değişiklik diğerlerini etkilemez.</li><li><strong>Bakım Kolaylığı:</strong> Küçük ve modüler yapılar sayesinde hataları tespit etmek ve düzeltmek çok daha kolaydır.</li><li><strong>Daha Temiz ve Düzenli Kod:</strong> Kodun parçalara ayrılması, okunabilirliği ve geliştirme sürecini hızlandırır.</li></ul><h4>2.2 React’te Bileşen Türleri</h4><p>React bileşenleri genel olarak Fonksiyonel Bileşenler (Functional Components) ve Sınıf Bileşenleri (Class Components) olmak üzere ikiye ayrılır.</p><p><strong>2.2.1 Fonksiyonel Bileşenler</strong></p><p>Günümüzde en çok kullanılan bileşen türüdür. Basit ve performans açısından verimli oldukları için React ekibi tarafından da önerilmektedir. Özellikler React Hooks sayesinde, eskiden yalnızca sınıf bileşenlerinde bulunan birçok özellik fonksiyonel bileşenlerde de kullanılabilir hale gelmiştir.</p><p>Bir fonksiyonel bileşen, JavaScript fonksiyonu gibi tanımlanır ve JSX döndürerek kullanıcı arayüzünü oluşturur:</p><pre>function Welcome(props) {<br>  return &lt;h1&gt;Merhaba, {props.name}!&lt;/h1&gt;;<br>}<br><br>export default Welcome;</pre><p>Bu bileşeni bir sayfada şu şekilde kullanabiliriz:</p><pre>&lt;Welcome name=&quot;Ahmet&quot; /&gt;</pre><p>Burada name adlı bir prop (özellik) kullanılmıştır. Props’lar sayesinde bileşenlere dinamik veri aktarabiliriz.</p><p><strong>2.2.2 Sınıf Bileşenleri</strong></p><p>React’in eski sürümlerinde yaygın kullanılan sınıf bileşenleri, ES&amp; sınıf yapısını kullanarak oluşturulur. Ancak, React 16.8 sürümüyle gelen Hooks sonrası sınıf bileşenlerine olan ihtiyaç azalmıştır.</p><p>Sınıf bileşeni örneği:</p><pre>import React, { Component } from &quot;react&quot;;<br><br>class Welcome extends Component {<br>  render() {<br>    return &lt;h1&gt;Merhaba, {this.props.name}!&lt;/h1&gt;;<br>  }<br>}<br><br>export default Welcome;</pre><p>Fonksiyonel bileşenlerle kıyaslandığında, sınıf bileşenleri daha uzun ve karmaşıktır. Ayrıca, “this” bağlamını yönetmek zorunda olduğumuz için hatalara daha açıktır.</p><h4>2.3 Props ve State Kullanımı</h4><p>React bileşenleri, iki temel veri yönetim aracı kullanılır: Props (Özellikler) ve State (Durum).</p><p><strong>2.3.1 Props Nedir?</strong></p><p>Props, bileşenlere dışarıdan aktarılan ve bileşen içinde değiştirilemeyen verilerdir. HTML etiketlerindeki attribute mantığına benzer şekilde çalışır.</p><p>Örnek kullanım:</p><pre>function UserCard(props) {<br>  return (<br>    &lt;div&gt;<br>      &lt;h2&gt;{props.name}&lt;/h2&gt;<br>      &lt;p&gt;Yaş: {props.age}&lt;/p&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>// Kullanımı:<br>&lt;UserCard name=&quot;Ahmet&quot; age={25} /&gt;</pre><p>Burada name ve age bilgileri bileşene props olarak iletilmiştir. Props’lar salt okunur (read-only) olduğundan bileşenin içinde değiştirilemez.</p><p><strong>2.3.2 State Nedir?</strong></p><p>State, bileşen içinde değişebilen verileri saklamak için kullanılır. Kullanıcı etkileşimi veya belirli bir olay gerçekleştiğinde state güncellenebilir.</p><p>Fonksiyonel bileşenlerde useState hook’u ile state yönetimi yapılır:</p><pre>import { useState } from &quot;react&quot;;<br><br>function Counter() {<br>  const [count, setCount] = useState(0);<br><br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;Sayac: {count}&lt;/p&gt;<br>      &lt;button onClick={() =&gt; setCount(count + 1)}&gt;Arttır&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default Counter;</pre><p>Burada useState(0) ile başlangıç değeri 0 olan bir state tanımlandı ve setCount fonksiyonu ile güncellendi.</p><h4>2.4 Bileşenler Arası Veri Akışı</h4><p>Bir React uygulamasında bileşenler genellikle parent-child ilişkisi içinde çalışır. Ancak, veri akışını yönetmek bazen zor olabilir.</p><p><strong>2.4.1 Props Drilling (Props Zinciri) Sorunu</strong></p><p>Eğer bir veri, birkaç seviye altındaki bir bileşene iletilmek istenirse, props’ların sürekli olarak bir sonraki bileşene aktarılması gerekir. Bu, Props Drilling olarak adlandırılır ve kodun okunurluğunu zorlaştırabilir.</p><p>Bu sorunu çözmek için:</p><ul><li>Context API</li><li>State Yönetim Kütüphaneleri (Redux, Zustand vs.)</li></ul><p>gibi yöntemler kullanılabilir.</p><p>Örneğin, Context API ile props drilling’i önleyebiliriz:</p><pre>import { createContext, useContext } from &quot;react&quot;;<br><br>const UserContext = createContext();<br><br>function Parent() {<br>  return (<br>    &lt;UserContext.Provider value=&quot;Ahmet&quot;&gt;<br>      &lt;Child /&gt;<br>    &lt;/UserContext.Provider&gt;<br>  );<br>}<br><br>function Child() {<br>  const user = useContext(UserContext);<br>  return &lt;h1&gt;Merhaba, {user}!&lt;/h1&gt;;<br>}</pre><p>Bu sayede user verisini doğrudan Child bileşeninde kullanabiliyoruz.</p><p>React bileşenleri, modern web geliştirmede kullanıcı arayüzlerini daha modüler, ölçeklenebilir ve yönetilebilir hale getiren önemli bir araçtır. Fonksiyonel ve sınıf bileşenleri arasındaki farkları bilmek, props ve state kavramlarını anlamak ve bileşenler arası veri akışını yönetebilmek, React ile sağlam uygulamalar geliştirmek için kritik öneme sahiptir.</p><h3>3. React Hooks</h3><p>React’in 16.8 sürümüyle birlikte tanıtılan Hooks, fonksiyonel bileşenlerin daha güçlü hale gelmesini sağladı. Önceden yalnızca sınıf bileşenlerinde mevcut olan state yönetimi, yaşam döngüsü metodları ve diğer bileşen özellikleri, Hooks sayesinde fonksiyonel bileşenlerde de kullanılabilir hale geldi.</p><p>Hooks kullanmanın en büyük avantajları şunlardır:</p><ul><li>Daha az kod ile daha fazla işlevsellik</li><li>Kod okunabilirliğini ve bakımını kolaylaştırma</li><li>Sınıf bileşenlerindeki “this” kullanımına gerek kalmaması</li><li>Kod tekrarını önleyerek daha temiz ve modüler yapı oluşturma</li></ul><h4>3.1 React Hooks Nedir?</h4><p>Hooks, fonksiyonel bileşenlerin state tutmasını ve yaşam döngüsü metodlarını kullanmasını sağlayan özel JavaScript fonksiyonlarıdır.</p><p>Hooks’lar şu kurallara uymak zorundadır:</p><ul><li>Yalnızca fonksiyonel bileşenler veya özel (custom) hook’lar içinde çağırılabilir.</li><li>Koşullu ifadeler, döngüler veya iç içe geçmiş fonksiyonlar içinde kullanılamaz.</li></ul><p>Örnek kullanım şu şekildedir:</p><pre>const [count, setCount] = useState(0);</pre><p>Şimdi en yaygın kullanılan React Hooks’lara bakalım.</p><p><strong>3.2 useState: State Yönetiminin Temelleri</strong></p><p>useState, bileşenin içindeki değişkenleri yeniden render edilmesini sağlayarak saklamak için kullanılır.</p><p>Örnek: Bir sayaç bileşeni:</p><pre>import { useState } from &quot;react&quot;;<br><br>function Counter() {<br>  const [count, setCount] = useState(0); // count state’ini tanımladık.<br><br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;Sayac: {count}&lt;/p&gt;<br>      &lt;button onClick={() =&gt; setCount(count + 1)}&gt;Arttır&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default Counter;</pre><ul><li>useState(0): count isimli state’in başlangıç değerini 0 olarak belirler.</li><li>setCount(count + 1): State’in yeni değerini belirler ve bileşeni yeniden render eder.</li></ul><p><strong>3.3 useEffect: Yan Etkileri Yönetmek</strong></p><p>useEffect, bileşenlerin yaşam döngüsünü yönetmek için kullanılır. Örneğin:</p><ul><li>API çağrıları yapmak</li><li>DOM manipülasyonu yapmak</li><li>Bir bileşen yüklendiğinde çalışması gereken kodları çalıştırmak</li></ul><p>Örnek: Bir sayfa yüklendiğinde bir mesaj göstermek:</p><pre>import { useState, useEffect } from &quot;react&quot;;<br><br>function App() {<br>  const [count, setCount] = useState(0);<br><br>  useEffect(() =&gt; {<br>    console.log(&quot;Bileşen ekrana geldi!&quot;);<br>  }, []); // [] bağımlılık dizisi, sadece bir kere çalışmasını sağlar.<br><br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;Sayac: {count}&lt;/p&gt;<br>      &lt;button onClick={() =&gt; setCount(count + 1)}&gt;Arttır&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>Bağımlılık Dizisi ( [ ] )</p><ul><li>Eğer bağımlılık dizisi boş bırakılırsa ( [ ] ), useEffect sadece bileşen ilk render edildiğinde çalışır.</li><li>Eğer bir değişken eklenirse ( [count] ), her count değiştiğinde çalışır.</li><li>Eğer bağımlılık dizisi yoksa, her render sonrası çalışır (istenmeyen performans sorunlarına yol açabilir).</li></ul><p>Örneğin, count değiştikçe çalışmasını istersek:</p><pre>useEffect(() =&gt; {<br>  console.log(`Sayaç değişti: ${count}`);<br>}, [count]);</pre><p><strong>3.4 useContext: Global State Yönetimi</strong></p><p>useContext, bileşenler arası veri paylaşımını kolaylaştırır. Props Drilling (props zinciri) sorununu çözmek için kullanılır.</p><p>Örnek: Kullanıcı adını global olarak paylaşmak:</p><pre>import { createContext, useContext } from &quot;react&quot;;<br><br>const UserContext = createContext();<br><br>function Parent() {<br>  return (<br>    &lt;UserContext.Provider value=&quot;Ahmet&quot;&gt;<br>      &lt;Child /&gt;<br>    &lt;/UserContext.Provider&gt;<br>  );<br>}<br><br>function Child() {<br>  const user = useContext(UserContext);<br>  return &lt;h1&gt;Merhaba, {user}!&lt;/h1&gt;;<br>}</pre><p>Böylece user bilgisi prop olarak aktarmaya gerek kalmadan doğrudan kullanılabilir.</p><p><strong>3.5 useReducer vs useState: Ne Zaman Hangisi Kullanılmalı?</strong></p><p>useReducer, state’i yönetmek için daha karmaşık ve yapılandırılmış bir alternatif sağlar.</p><p>Basit state değişiklikleri için useState kullanılır.</p><pre>const [count, setCount] = useState(0);</pre><p>Ancak büyük ve karmaşık state yapılarında useReducer önerilir.</p><p>Örneğin, bir todo uygulaması için:</p><pre>import { useReducer } from &quot;react&quot;;<br><br>function reducer(state, action) {<br>  switch (action.type) {<br>    case &quot;increment&quot;:<br>      return { count: state.count + 1 };<br>    case &quot;decrement&quot;:<br>      return { count: state.count - 1 };<br>    default:<br>      return state;<br>  }<br>}<br><br>function Counter() {<br>  const [state, dispatch] = useReducer(reducer, { count: 0 });<br><br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;Sayac: {state.count}&lt;/p&gt;<br>      &lt;button onClick={() =&gt; dispatch({ type: &quot;increment&quot; })}&gt;Arttır&lt;/button&gt;<br>      &lt;button onClick={() =&gt; dispatch({ type: &quot;decrement&quot; })}&gt;Azalt&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>Ne zaman useReducer Kullanmalıyım?</p><ul><li>Büyük ve karmaşık state yönetimi gerekiyorsa</li><li>State’in farklı şekillerde güncellenmesi gerekiyorsa</li><li>Birden fazla state değeri yönetilicekse</li></ul><p><strong>3.6 Özel (Custom) Hook’lar ve Kullanım Alanları</strong></p><p>Eğer bir işlemi birçok bileşende tekrar tekrar yapmak gerekiyorsa, özel Hook (Custom Hook) tanımlayarak kod tekrarını önleyebiliriz.</p><p>Örneğin, pencere genişliğini takip eden bir custom hook oluşturalım:</p><pre>import { useState, useEffect } from &quot;react&quot;;<br><br>function useWindowWidth() {<br>  const [width, setWidth] = useState(window.innerWidth);<br><br>  useEffect(() =&gt; {<br>    const handleResize = () =&gt; setWidth(window.innerWidth);<br>    window.addEventListener(&quot;resize&quot;, handleResize);<br><br>    return () =&gt; {<br>      window.removeEventListener(&quot;resize&quot;, handleResize);<br>    };<br>  }, []);<br><br>  return width;<br>}<br><br>function App() {<br>  const width = useWindowWidth();<br><br>  return &lt;h1&gt;Pencere genişliği: {width}px&lt;/h1&gt;;<br>}</pre><p>Böylece useWindowWidth Hook’unu istediğimiz bileşende kolayca kullanabiliriz.</p><p>React Hooks, modern React uygulamalarını daha modüler, okunabilir ve yönetilebilir hale getiren güçlü araçlardır. useState, useEffect, useContext, useReducer gibi temel Hooks’ları iyi anlamak, React’te ileri seviye geliştirme yapabilmek için kritik öneme sahiptir.</p><h3>4. React’te DOM (Document Object Model) Yönetimi</h3><p>React’in en güçlü yönlerinden biri, DOM yönetimini optimize etmesi ve geliştiricilere verimli bir şekilde UI oluşturma imkanı sunmasıdır. Geleneksel JavaScript ve jQuery’de DOM manipülasyonu doğrudan yapılırken, React Sanal bir DOM (Virtual DOM) kullanarak bu süreci çok daha verimli hale getirir.</p><p><strong>4.1 DOM ve Virtual DOM Farkı</strong></p><p>Öncelikle, DOM (Document Object Model) ve Virtual DOM arasındaki farkı anlamak önemlidir.</p><p>🔴 Geleneksel DOM:</p><ul><li>HTML belgesinin ağaç yapısıdır ve her bir öğe (element) bir düğüm (node) olarak temsil edilir.</li><li>JavaScript ile doğrudan manipüle edilebilir.</li><li>Performans sorunları yaratabilir, çünkü her değişiklikte tüm sayfanın veya büyük bir kısmının yeniden işlenmesi gerekir.</li></ul><p>🟢 Virtual DOM (Sanal DOM):</p><ul><li>React’in hafızada tuttuğu hafif bir kopyadır.</li><li>Gerçek DOM ile birebir aynıdır, ancak değişiklikler doğrudan gerçek DOM’a uygulanmaz.</li><li>Diffing (karşılaştırma) algoritması ile önce değişiklikler tespit edilir, sonra yalnızca ilgili kısımlar güncellenir.</li><li>Performansı artırır ve gereksiz render işlemlerini önler.</li></ul><p>Örnek olarak, bir React bileşeninde setState çağrıldığında:</p><ul><li>Yeni Virtual DOM oluşturulur.</li><li>Eski ve yeni Virtual DOM karşılaştırılır.</li><li>Sadece değişen kısımlar gerçek DOM’a uygulanır.</li></ul><p>Bu yöntem, sayfanın çok daha hızlı çalışmasını sağlar.</p><p><strong>4.2 React’te DOM Manipülasyonu</strong></p><p>React’te genellikle doğrudan DOM manipülasyonu yapmayız, çünkü Virtual DOM bu işi bizim için optimize eder. Ancak, bazen belirli durumlarda doğrudan DOM’a erişmek gerekebilir.</p><p>Örnek: Geleneksel JavaScript’te DOM güncellemesi</p><pre>&lt;button onclick=&quot;document.getElementById(&#39;text&#39;).innerHTML = &#39;Merhaba!&#39;&quot;&gt;<br>  Güncelle<br>&lt;/button&gt;<br>&lt;p id=&quot;text&quot;&gt;Merhaba, dünya!&lt;/p&gt;</pre><p>Aynı işlem React ile daha verimli ve yönetilebilir bir şekilde yapılır:</p><pre>import { useState } from &quot;react&quot;;<br><br>function App() {<br>  const [text, setText] = useState(&quot;Merhaba, dünya!&quot;);<br><br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;{text}&lt;/p&gt;<br>      &lt;button onClick={() =&gt; setText(&quot;Merhaba!&quot;)}&gt;Güncelle&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>Neden React Daha Verimli?</p><ul><li>Virtual DOM değişiklikleri optimize eder.</li><li>Gerçek DOM yerine, yalnızca değişen öğeler güncellenir.</li><li>React’in iç mekanizması sayesinde gereksiz yeniden render işlemleri engellenir.</li></ul><p><strong>4.3 React.Fragment ile Gereksiz DOM Elemanlarını Önlemek</strong></p><p>Normalde bir React bileşeni tek bir kapsayıcı &lt;div&gt; etiketi içinde döndürülmelidir. Ancak gereksiz &lt;div&gt; kullanımı DOM’u şişirebilir.</p><p>Örnek: Fazladan &lt;div&gt; içeren kod</p><pre>function List() {<br>  return (<br>    &lt;div&gt; {/* Gereksiz bir &lt;div&gt; eklenmiş */}<br>      &lt;h1&gt;Başlık&lt;/h1&gt;<br>      &lt;p&gt;Bu bir paragraf.&lt;/p&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>Bunun yerine, React.Fragment ( &lt;&gt; &lt;/&gt; ) kullanarak gereksiz &lt;div&gt; eklememiş oluruz:</p><pre>function List() {<br>  return (<br>    &lt;&gt;<br>      &lt;h1&gt;Başlık&lt;/h1&gt;<br>      &lt;p&gt;Bu bir paragraf.&lt;/p&gt;<br>    &lt;/&gt;<br>  );<br>}</pre><ul><li>Daha temiz ve performanslı bir DOM oluşturur.</li><li>Ekstra gereksiz HTML elementleri eklenmez.</li></ul><p><strong>4.4 useRef ile Doğrudan DOM Erişimi</strong></p><p>React’te bazen doğrudan DOM öğelerine erişmek gerekebilir (örneğin, bir input alanına otomatik odaklanmak). Bunun için useRef kullanılır.</p><p>Örnek: Bİr input alanına odaklanmak</p><pre>import { useRef, useEffect } from &quot;react&quot;;<br><br>function InputFocus() {<br>  const inputRef = useRef(null);<br><br>  useEffect(() =&gt; {<br>    inputRef.current.focus(); // Sayfa yüklendiğinde inputa odaklan<br>  }, []);<br><br>  return &lt;input ref={inputRef} placeholder=&quot;Buraya yaz...&quot; /&gt;;<br>}<br><br>export default InputFocus;</pre><p>useRef Kullanım Alanları:</p><ul><li>DOM öğelerine doğrudan erişmek (focus, scroll vb.)</li><li>Değişkenleri state değiştirmeden saklamak</li><li>Bir bileşenin önceki değerini hatırlamak</li></ul><p><strong>4.5 React Portals ile DOM’uun Dışına Render Etme</strong></p><p>Bazı durumlarda, React bileşenlerini mevcut DOM hiyerarşisinin dışında bir yere eklemek isteyebiliriz. Örneğin:</p><ul><li>Modallar (Açılır Pencereler)</li><li>Tooltip’ler (İpucu Baloncukları)</li><li>Dropdown Menüler</li></ul><p>Bu gibi durumlarda, React Portals kullanılır.</p><p>Örnek: Bir modal penceresi</p><ul><li>HTML içinde bir portal kapsayıcı ekleyelim:</li></ul><pre>&lt;div id=&quot;modal-root&quot;&gt;&lt;/div&gt;</pre><ul><li>React içinde Portals kullanımı:</li></ul><pre>import { useState } from &quot;react&quot;;<br>import ReactDOM from &quot;react-dom&quot;;<br><br>function Modal({ children }) {<br>  return ReactDOM.createPortal(<br>    &lt;div className=&quot;modal&quot;&gt;{children}&lt;/div&gt;,<br>    document.getElementById(&quot;modal-root&quot;)<br>  );<br>}<br><br>function App() {<br>  const [showModal, setShowModal] = useState(false);<br><br>  return (<br>    &lt;div&gt;<br>      &lt;button onClick={() =&gt; setShowModal(true)}&gt;Modal Aç&lt;/button&gt;<br>      {showModal &amp;&amp; (<br>        &lt;Modal&gt;<br>          &lt;h2&gt;Bu bir modal!&lt;/h2&gt;<br>          &lt;button onClick={() =&gt; setShowModal(false)}&gt;Kapat&lt;/button&gt;<br>        &lt;/Modal&gt;<br>      )}<br>    &lt;/div&gt;<br>  );<br>}</pre><p>React Portals’ın Avantajları:</p><ul><li>Bileşeni ana DOM ağacının dışında render edebiliriz.</li><li>Modal gibi öğeler, mevcut sayfa düzenini bozmaz.</li><li>Z-index, overflow gibi CSS sorunlarını önler.</li></ul><p>React’te DOM yönetimi performans ve verimlilik açısından kritik bir konudur.</p><ul><li>Virtual DOM, geleneksel DOM’a göre çok daha hızlıdır.</li><li>React.Fragment gereksiz DOM düğümlerini önler.</li><li>useRef, doğrudan DOM erişimini kolaylaştırır.</li><li>React Portals, DOM’un dışına bileşen render etmeyi sağlar.</li></ul><h3>Sonuç ve Genel Değerlendirme</h3><p>Bu makalede, React’in temel yapı taşlarını detaylı bir şekilde ele aldık. React’in en büyük avantajlarından biri, bileşen tabanlı mimarisi, Hooks kullanımı ve Virtual DOM ile verimli bir şekilde çalışmasıdır.</p><p>Özetle şunları öğrendik:</p><ul><li>React Hooks, bileşenlerin state ve yan etkileri yönetmesini sağlar.</li><li>React Bileşenleri, UI’yi modüler ve tekrar kullanılabilir hale getirir.</li><li>React’te DOM Yönetimi, Virtual DOM sayesinde optimize edilir ve gereksiz render işlemlerinden kaçınılır.</li></ul><p>React, modern web uygulamaları geliştirmek için hızlı, ölçeklenebilir ve esnek bir çözüm sunar.</p><p>GitHub — <a href="https://github.com/YusufEfe058">YusufEfe058</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c4634d66d17" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vue.js Nedir? Neden Tercih Edilir? Nasıl Kurulur?]]></title>
            <link>https://medium.com/@yusufefe417/vue-js-nedir-86b70624925c?source=rss-622544ed7a5d------2</link>
            <guid isPermaLink="false">https://medium.com/p/86b70624925c</guid>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Yusuf Efe]]></dc:creator>
            <pubDate>Sun, 26 Jan 2025 21:36:28 GMT</pubDate>
            <atom:updated>2025-01-26T21:40:23.264Z</atom:updated>
            <content:encoded><![CDATA[<h3>Vue.js Nedir?</h3><p>Vue.js, kullanıcı arayüzü (UI) ve tek sayfalı uygulamalar oluşturmayı sağlayan, açık kaynaklı bir Javascript kütüphanesidir. Vue.js ile modern, küçük, orta ve büyük ölçekli mobil ve masaüstü uygulamalar oluşturmak mümkündür.</p><p>Document Object Model (DOM) üzerinde değişiklik yapmak maliyetli olduğu için Vue.js Virtual DOM kullanır. MVVM (Model-Görünüm-Görünüm Modeli) mimari deseni kullanır ve bu mimari modelin GUI (Grafik Kullanıcı Arayüzü) ve görünümden ayırt edilmesini sağlar. Bu ayrım, Front-end ve Backend geliştiricilerin birlikte çalışmasını sağlar.</p><h3>Vue.js Neden Tercih Ediliyor?</h3><p>Günümüzde en çok kullanılan Javascript kütüphanelerinden birisi olan Vue.js’yi kullanan çok sayıda geliştirici bulunmaktadır. Ayrıca geliştiricilerin sürümler, güncellemeler ve sorunlar hakkında konuşabilecekleri çok sayıda forum siteleri bulunur. Vue.js’nin popüler bir kütüphane olmasının nedenleri şunlardır:</p><ul><li>Kolay ve hızlı öğrenilebilen bir yapı,</li><li>Sade ve anlaşılır dökümantasyonlar,</li><li>İhtiyaçlara göre şekil alabilmesi,</li><li>projelere kolay entegre edilebilmesi,</li><li>Rakiplerine göre hızlı olması,</li><li>Rakiplerine göre projelere çok daha kolay adapte olması.</li></ul><h3>Vue.js’in Tarihi</h3><p>Vue.js, 2014 yılında Evan You tarafından geliştirildi. Vue.js’in temel motivasyonu, geliştirici deneyimini iyileştiren, hafif ve esnek bir framework oluşturmaktı. Evan You, Google’da çalışırken AngularJS ile edindiği deneyimlerinden yola çıkarak AngularJS’in karmaşıklıklarından arındırılmış bir çekirdek yapı tasarlamaya karar verdi.</p><p>İlk sürümü 2014&#39;te yayınlanan Vue.js, başlangıçta küçük bir proje olarak geliştirildi. Ancak, sağladığı basitlik ve esneklik sayesinde geliştiriciler arasında hızla popüler oldu. Topluluk desteğinin artması ve Vue.js ekosisteminin gelişmesiyle framework, çeşitli ölçeklerdeki projelerde kullanılmaya başlandı.</p><p>2016 yılında Vue.js 2 sürümü piyasaya sürüldü. Bu sürümde sanal DOM, reaktif veri bağlama ve performans iyileştirmeleri gibi yenilikler tanıtıldı. Vue 2, geliştiricilere daha esnek bir yapı ve daha iyi performans sundu.</p><p>2020 yılında Vue 3, çok önemli bir güncelleme olarak yayımlandı. Vue 3 ile birlikte Composition API tanıtıldı ve framework daha modüler hale getirildi. Bu yeni API, büyük ve karmaşıkk uygulamaların daha kolay geliştirilmesini mümkün kıldı. Ayrıca Vue 3, daha iyi performans ve daha küçük bir paket boyutu sunarak mordern tarayıcılarla uyumlu hale geldi.</p><p>Bugün Vue.js, geliştiri topluluklarında ççok yaygın olarak kullanılan, esnek ve çok yönlü bir framework olarak kabul edilmektedir. Evan You ve Vue.js ekibi, frameworkü geliştirmeye devam etmekte ve gelecekteki yenilikler için planlar yapmaktadır.</p><h3>Vue.js’in Temel Özellikleri</h3><h4>1. Reaktif Veri Bağlama</h4><p>Vue.js, reaktif bir veri modeli sunarak HTML ile veri arasında senkronizasyon sağlar. Bu sayede, veride meydana gelen değişiklikler otomatik olarak kullanıcı arayüzüne yansıtılır.</p><h4>2. Sanal DOM (Virtual DOM)</h4><p>Vue.js, DOM manipülasyonlarını optimize etmek için Sanal Dom kullanır. Bu teknoloji, sayfa performansını arttırır ve uygulamaları daha hızlı hale getirir.</p><h4>3. Bileşen Tabanlı Mimari</h4><p>Vue.js, uygulamaları yeniden kullanabilir bileşenlere ayırır. Bu yapı, kodun daha düzenli ve modüler olmasını sağlar.</p><h4>4. Direktifler</h4><p>Vue.js, HTML’i zenginleştiren v-bind, v-if, v-for gibi birççok direktif sunar. Bu direktifler, veri ve DOM arasındaki bağlantıyı kolayca kurmaya olanak tanır.</p><h4>5. İki Yönlü Veri Bağlama (Two-Way Data Binding)</h4><p>Vue.js, v-model direktifi aracılığıyla iki yönlü veri bağlama sağlar. Bu özellik, form elemanlarıyla çalışmayı oldukça kolaylaştırır.</p><h4>6. Vue Router</h4><p>Vue.js, SPA (Single Page Application) uygulamaları için Vue Router adında entegre bir yönlendirme sistemi sunar. bu sistem, uygulama içerisinde kolayca sayfa yönlendirme yapılmasını sağlar.</p><h4>7. Vuex</h4><p>Vuex, Vue.js projelerinde global durum yönetimi için kullanılır. State, mutations, actions ve getters gibi yapılarla karmaşık uygulamalarda kolay yönetim sağlar.</p><h4>8. Performans Optimizasyonu</h4><p>Vue.js lazy loading, async bileşenler ve dinamik import gibi özelliklerle performansı optimize eder.</p><h4>9. Topluluk ve Ekosistem Desteği</h4><p>Vue.js, geniş bir geliştirici topluluğu ve zzengin bir ekosistem sunar. Nuxt.js, Vue DevTools ve birçok eklenti bu ekosistemin parçalarından bazılarıdır.</p><h3>Vue.js Kurulumu</h3><h4>1. CDN üzerinden Kullanım</h4><p>Vue.js’i hızlıca denemek için bir CDN bağlantısı kullanabilirsiniz. HTML dosyanıza aşağıdaki script etiketi eklenerek Vue.js yüklenebilir:</p><pre>&lt;script src=&quot;https://cdn.jsdelivr.net/npm/vue@3&quot;&gt;&lt;/script&gt;</pre><h4>2. Vue CLI ile Proje Oluşturma</h4><p>Vue CLI, Vue.js projelerini hızlıca başlatmanıza olanak tanıyan bir aracıdır. Vue CLI kullanarak bir proje oluşturmak için şu adımlar izlenir:</p><ul><li>Node.js ve npm’in bilgisayarınızda kurulu olduğundan emin olun.</li><li>Vue. CLI’yı kurun:</li></ul><pre>npm install -g @vue/cli</pre><ul><li>Yeni bir Vue projesi oluşturun:</li></ul><pre>vue create my-project</pre><ul><li>Projenize gidin ve başlatın:</li></ul><pre>cd my-project<br>npm run serve</pre><ul><li>Tarayıcınızda <a href="http://localhost:8080/">http://localhost:8080</a> adresine giderek projenizi görebilirsiniz.</li></ul><h4>3. Vue.js’i Paket Yöneticileri ile Kurma</h4><p>Vue.js’i bir projeye dahil etmek için npm veya yarn gibi paket yöneticilerini kullanabilirsiniz:</p><pre>npm install vue<br><br><br><br>yarn add vue</pre><p>Bu yöntem, Vue.js’i mevcut bir projeye dahil etmek için idealdir.</p><h4>4. Vite ile Kurulum</h4><p>Vite, Vue.js projelerini hızlıca başlatmanıza olanak tanıyan modern bir build aracıdır. Vite kullanarak bir proje oluşturmak için:</p><ul><li>Proje dizini oluşturun:</li></ul><pre>mkdir my-vue-app<br>cd my-vue-app</pre><ul><li>Vite’ı kullanarak proje oluşturun:</li></ul><pre>npm create vite@latest</pre><ul><li>Vue.js seçeneğini seçin ve adımları tamamlayın.</li><li>Bağımlılıkları yükleyin ve projeyi başlatın:</li></ul><pre>npm install<br>npm run dev</pre><h4>Hangi Yöntem Seçilmeli?</h4><p>Hangi kurulum yöntemini kullanacağınız, projenizzin karmaşıklığına ve amacına bağlıdır. Basit bir demo için CDN kullanımı uygunken, çok daha büyük ve karmaşık projelerde Vue CLI veya Vite tercih edilmelidir.</p><h3>Vue.js Bileşenleri</h3><h4>1. Bileşenlerin Temelleri</h4><p>Vue.js’de bir bileşen, Vue instanceından türetilen bir nesnedir. Bileşenler genellikle HTML, CSS ve JavaScript’i bir arada barındırarak tek bir şablon içerisinde tanımlanır.</p><pre>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;h1&gt;{{ title }}&lt;/h1&gt;<br>    &lt;p&gt;{{ description }}&lt;/p&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br><br>&lt;script&gt;<br>export default {<br>  name: &#39;MyComponent&#39;,<br>  data() {<br>    return {<br>      title: &#39;Merhaba Vue!&#39;,<br>      description: &#39;Bu bir bileşen örneğidir.&#39;<br>    };<br>  }<br>};<br>&lt;/script&gt;<br><br>&lt;style scoped&gt;<br>  h1 {<br>    color: blue;<br>  }<br>&lt;/style&gt;</pre><p>Yukarıdaki örnekte ‘MyComponent’ adında bir bileşen oluşturulmuştur. Bu bileşen, bir başlık ve bir aççıklama metni görüntüler.</p><h4>2. Bileşenin Türleri</h4><p>Vue.js’’de bileşenler, genellikle iki ana kategoriye ayrılır:</p><p>a. Yerel Bileşenler (Local Components)</p><p>Yerel bileşenler, belirli bir Vue instance veya bileşen içerisinde tanımlanır ve sadece o bileşen içinde kullanılabilir.</p><pre>import MyComponent from &#39;./MyComponent.vue&#39;;<br><br>export default {<br>  components: {<br>    MyComponent<br>  }<br>};</pre><p>b. Genel Bileşenler (Global Components)</p><p>Genel bileşenler, Vue instance seviyesinde kaydedilir ve uygulamaların herhangi bir yerinde kullanılabilir.</p><pre>import MyComponent from &#39;./MyComponent.vue&#39;;<br><br>Vue.component(&#39;my-component&#39;, MyComponent);</pre><h4>3. Props ve Events</h4><p>Vue.js bileşenleri, ebeveyn ve çocuk bileşenler arasında iletişim kurmak için props ve events mekanizmasını kullanır.</p><p>a. Props</p><p>Props, ebeveyn bileşenden çocuğa veri aktarmak için kullanılır.</p><pre>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;h1&gt;{{ title }}&lt;/h1&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br><br>&lt;script&gt;<br>export default {<br>  props: [&#39;title&#39;]<br>};<br>&lt;/script&gt;</pre><p>b. Events</p><p>Events, çocuk bileşenden ebeveyne mesaj iletmek için kullanılır. Bu mekanizma this.$emit ile gerççekleştirilir.</p><pre>&lt;template&gt;<br>  &lt;button @click=&quot;handleClick&quot;&gt;Tıkla&lt;/button&gt;<br>&lt;/template&gt;<br><br>&lt;script&gt;<br>export default {<br>  methods: {<br>    handleClick() {<br>      this.$emit(&#39;custom-event&#39;, &#39;Mesaj&#39;);<br>    }<br>  }<br>};<br>&lt;/script&gt;</pre><h4>4. Dinamik ve Asenkron Bileşenler</h4><p>a. Dinamik Bileşenler</p><p>Vue.js, component etiketi ile dinamik bileşen yüklemeyi destekler.</p><pre>&lt;template&gt;<br>  &lt;component :is=&quot;currentComponent&quot;&gt;&lt;/component&gt;<br>&lt;/template&gt;<br><br>&lt;script&gt;<br>export default {<br>  data() {<br>    return {<br>      currentComponent: &#39;MyComponent&#39;<br>    };<br>  }<br>};<br>&lt;/script&gt;</pre><p>b. Asenkron Bileşenler</p><p>Asenkron bileşenler, ihtiyaç duyulduğunda yüklenir. Bu, uygulamaların performansını iyileştirir.</p><pre>Vue.component(&#39;my-async-component&#39;, () =&gt; import(&#39;./MyComponent.vue&#39;));</pre><h4>5. Slot Kullanımı</h4><p>Vue.js’de slotlar, bileşenlere esneklik sağlar ve çocuk bileşenlerin içeriğini ebeveyn bileşenlerde tanımlamaya olanak tanır.</p><p>Temel Slot:</p><pre>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;slot&gt;&lt;/slot&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;</pre><p>Adlandırılmış Slot:</p><pre>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;slot name=&quot;header&quot;&gt;&lt;/slot&gt;<br>    &lt;slot&gt;&lt;/slot&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;</pre><h4>6. Bileşen Yaşam Döngüsü</h4><p>Vue.js bileşenleri, oluşturma (create), DOM’a ekleme (mount), güncelleme (update) ve yok etme (destroy) gibi farklı aşamalardan geçer. Yaşam döngüsü işlevleri, geliştiricilere belirli aşamalarda özel işlevler çağırma imkanı tanır.</p><pre>export default {<br>  created() {<br>    console.log(&#39;Bileşen oluşturuldu.&#39;);<br>  },<br>  mounted() {<br>    console.log(&#39;Bileşen DOM’a eklendi.&#39;);<br>  }<br>};</pre><p>Vue.js bileşenleri, uygulamaların daha modüler, yeniden kullanılabilir ve esnek hale gelmesini sağlar. Doğru bir bileşen yapısı kurarak, geliştirme sürecini hem hızlandırabilir hem de uzun vadede daha sürekli bir kod tabanına ulaşabilirsiniz.</p><p>Sonuç olarak, Vue.js, esnekliği, kolay öğrenilebilirliği ve güçlü özellikleri sayesinde modern web geliştirme dünyasında kendine sağlam bir yer edinmiştir. Hem yeni başlayanlar hem de deneyimli geliştiriciler için uygun bir framework olan Vue.js, bileşen tabanlı yapısı, güçlü ekosistemi ve performans odaklı çözümleriyle projelere değer katmaktadır. Sürekli geliştirilen ve desteklenen bir topluluk tarafından desteklenen Vue.js gelecekte de popüleritisini koruyacak ve modern web teknolojilerinin şekillenmesinde önemli rol oynayacaktır. :)</p><p>GitHub — <a href="https://github.com/YusufEfe058">YusufEfe058</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86b70624925c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>