<?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 Erdem Besler on Medium]]></title>
        <description><![CDATA[Stories by Erdem Besler on Medium]]></description>
        <link>https://medium.com/@erdembesler?source=rss-7129056dd3f3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*hhnfDxbdVrPvxaXZ</url>
            <title>Stories by Erdem Besler on Medium</title>
            <link>https://medium.com/@erdembesler?source=rss-7129056dd3f3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 05:09:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@erdembesler/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 - Controlled vs Uncontrolled Components]]></title>
            <link>https://erdembesler.medium.com/react-controlled-vs-uncontrolled-components-aa697164cefb?source=rss-7129056dd3f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa697164cefb</guid>
            <dc:creator><![CDATA[Erdem Besler]]></dc:creator>
            <pubDate>Fri, 14 May 2021 18:40:30 GMT</pubDate>
            <atom:updated>2021-05-14T18:40:30.299Z</atom:updated>
            <content:encoded><![CDATA[<p>Components are the main feature of React. Controlled and Uncontrolled components are the only component types that react supports.</p><p>In React <a href="https://reactjs.org/docs/forms.html#controlled-components">doc</a> it is stated that we should use controlled components to implement forms in most cases. React component handles form data in the controlled components. On the other hand, form data is handled by the DOM it self in uncontrolled component.</p><p>Let’s deep dive into these two type of components.</p><h3>Controlled Components</h3><p>In HTML, form elements such as &lt;input&gt;, &lt;textarea&gt;, and &lt;select&gt; typically maintain their own state and update it based on user input. In React, mutable state is typically kept in the state property of components, and only updated with <a href="https://reactjs.org/docs/react-component.html#setstate">setState()</a>.</p><p>By making the React state the “single source of truth,” we can combine the two. The React component that renders a form then has control over what happens in that form when the user enters input. A “controlled component” is an input form element whose value is managed by React in this way.</p><p>Let’s look at a code example below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/504f1a6a6dd35d109113422dc173f3d0/href">https://medium.com/media/504f1a6a6dd35d109113422dc173f3d0/href</a></iframe><p>The state object is created on line 4 of the code for this component. It holds a single property called message. This is where the value that is entered into the textbox is stored.</p><p>In order to store the value, when the user types in the textbox we need an event to be triggered. If you look at line 24, you can see the facts that the textbox has a value attribute bound to the message property in the state and we have an onChange event handler declared. These 2 facts indicates that this is a controlled component.</p><p>After a change on the input element the handler is triggered. The handler calls setstate() as it is seen on line 11. This updates the state accordingly.</p><p>With a controlled component, the input’s value is always driven by the React state. While you’ll have to put a little more code as a result, you’ll be able to pass the value to other UI elements and reset it from other event handlers.</p><h3><strong>Uncontrolled Components</strong></h3><p>Instead of writing an event handler for every state update, you can <a href="https://reactjs.org/docs/refs-and-the-dom.html">use a ref</a> to get form values from the DOM to write an uncontrolled component.</p><p>Uncontrolled components act more like traditional HTML form elements. The data for each input element is stored in the DOM, not in the component. Instead of writing an event handler for every state update, you can <a href="https://reactjs.org/docs/refs-and-the-dom.html">use a ref</a> to get form values from the DOM to write an uncontrolled component.</p><p>For example, this code accepts a single name in an uncontrolled component:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/afb5b21ea83dbeeff724bfc81a329794/href">https://medium.com/media/afb5b21ea83dbeeff724bfc81a329794/href</a></iframe><p>Since an uncontrolled component keeps the source of truth in the DOM, it is sometimes easier to integrate React and non-React code when using uncontrolled components. It can also be slightly less code if you want to be quick and dirty.</p><h3>When to use controlled components and when to use uncontrolled components</h3><p>The advantages of both the controlled and uncontrolled form fields cannot be overstated. Evaluate your specific situation and choose an approach based on what works best for you.</p><p>Uncontrolled with refs is perfectly ok if your form is really simple in terms of UI feedback. You are not required to listen to what the various articles claim to be “bad.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jx9GytJ8iUm3DcqxYQSX5w.png" /></figure><p>If instant field validation, conditionally disabling submit button, enforcing input format, several inputs for one piece of data or dynamic inputs are required controlled inputs should be used. Otherwise, It is totally your decision to use controlled or uncontrolled component.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa697164cefb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CSS Architecture: Goals and Best Practices]]></title>
            <link>https://erdembesler.medium.com/css-architecture-9dc6be77e70f?source=rss-7129056dd3f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/9dc6be77e70f</guid>
            <dc:creator><![CDATA[Erdem Besler]]></dc:creator>
            <pubDate>Thu, 13 May 2021 00:10:07 GMT</pubDate>
            <atom:updated>2021-08-15T16:10:55.058Z</atom:updated>
            <content:encoded><![CDATA[<p>CSS is a simple language. Its basic purpose is to define selectors to target HTML elements and apply attributes to them, which is easy to grasp. When working on large and complex projects, though, some CSS features might be a little trickier to deal with.</p><p>On the DOM, elements also inherit properties from their parents. Additionally, it allows other selectors to override properties based on their order on the sheet or selector specificity. This can easily get out of control and chaotic if not well organized. This is where CSS architecture comes in handy.</p><p>A <strong>CSS architecture </strong>brings reasoning to CSS authoring. Imagine it as a collection of guidelines and best practices to help developers write code that’s predictable, maintainable, scalable and more reusable. The goals of good CSS architecture, in my opinion, should be similar to the goals of all good software development.</p><p>As it is stated, there are 4 main <strong>goals of a good CSS architecture, </strong>which are to make CSS:</p><ul><li><strong>Predictable: </strong><br>CSS that is predictable means that your rules will act as you expect them to. When you add or change a rule, it should not have an unintended effect on other sections of your site. This isn’t as critical on small sites that don’t change much, but it is on large sites</li><li><strong>Reusable:</strong><br>CSS rules should be abstract and decoupled enough that you can easily create new components from existing parts without recoding patterns and problems you’ve already solved.</li><li><strong>Scalable:<br></strong>If your site increases in size and complexity, you’ll probably need more developers to keep it running. CSS that is scalable can be handled by a single individual or a large engineering team with ease.</li><li><strong>Maintainable:</strong><br>When new components and features are implemented, modified, or rearranged on your page, existing CSS should not need to be refactored.</li></ul><p>In an environment that many people disagree over even the basic things CSS authors should and shouldn’t do, it is not possible to make a common definition of CSS or what to “exactly” to do in order for us to achieve good architecture. Following the best practices outlined below, however, will ensure that your CSS is predictable, reusable, scalable, and maintainable.</p><p><strong>BEST PRACTICES</strong></p><p><strong>1- Be intentional</strong></p><p>The more complex a selector is, the more tightly it is bound to HTML. Using HTML tags and combinators keeps your HTML tidy, but it makes your CSS dirty.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/325/1*ddhf6mPSTKVtbIFXvdv7lw.png" /></figure><p>All of the above examples make logical sense, right? If and only if this HTML were never going to change YES they do but, how realistic is it to assume the HTML will never change?</p><p>These examples are not reusable in any way. How does another component with a different HTML structure reuse those styles if the selector points to a specific location in the markup? Consider the first selector: what if a similar-looking component was required on a different page that wasn’t contained within the #main-search element? You’d have to recreate the entire style.</p><p>If the HTML needs to be modified, these selectors are also very unpredictable. If a developer replaced the &lt;div&gt; in the third example with the &lt;section&gt; tag, the entire rule will be broken.</p><p>Finally, since these selectors only work if the HTML stays stable, they’re not maintainable or scalable by definition.</p><p>The best way to make sure your selectors don’t style unwanted elements is to not give them the opportunity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/248/1*reLS7foW1FngzgMKEby4Qw.png" /></figure><p>A selector like #main-search ul li ul li div could very easily leads unwanted elements as your HTML structure changes . A style like .subsearch, on the other hand, has no risk of being applied to an undesirable feature by mistake.</p><p>The best way to keep your CSS predictable is to apply classes directly to the elements you want to style.</p><p><strong>2- Separate your concerns</strong></p><p>Components should be able to style themselves and do so well, but they should not be in charge of their layout or positioning, nor should they make too many assumptions about how they’ll be positioned in relation to other components.</p><p>Lets deep dive into the rule set below! You could create a visual component that needs to be 10 pixels from the top left corner of a website section:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/229/1*mL1fY6zM4XRNF4SkNYjH4w.png" /></figure><p>Then you’ll need to use this exact same part in a different location down the road. Since the above CSS isn’t reusable in various contexts, it won’t work.<br>The issue is that you’re doing too much of this single selector. Within the same rule, you’re determining the look, as well as the layout and position.</p><p>While this can seem to be harmless at first, it frequently leads to copying and pasting from developers who are less CSS-savvy. If a new team member wants something to look like a specific component, such as an .right-block, they’ll will start with that class. But, if that doesn’t work because it places the new block in an undesirable position, what will they do? They’ll probably only copy and paste the lines of code required for this specific instance into a new selector, duplicating code unnecessarily.</p><p><strong>3- Namespace your classes</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/332/1*9KlM3Vg6rnDb_YEdL9bxXA.png" /></figure><p>Almost every site has a visual feature that looks the same in every instance, with the exception of one. And when faced with this one-off situation almost every new CSS developer (and even experienced ones) handles it the same way. You find (or create) a special parent for this one specific occurrence, and you write a new rule to handle it.</p><p>The code above will appear to be fairly harmless at first glance, but let’s review it in light of the objectives set out above.</p><p>First, the widget in the example is not predictable. A developer who’s made several of these widgets will expect it to look a certain way, yet when she uses it in the sidebar or on the homepage, it will look different, despite the markup being exactly the same.</p><p>First, the widget in the example is not predictable. Even if the markup is identical, a developer who has created some of these widgets would expect it to look a certain way when the developer uses it in the sidebar or on the homepage.</p><p>Furthermore, it isn’t very scalable or reusable. What happens if you want it to look as it does on the homepage on another page? It would be necessary to add new rule set.</p><p>Lastly, it’s difficult to manage because if the widget is redesigned, it will need to be revised in many places in the CSS. So, it is not maintainable too.</p><p><strong>A much better approach is</strong> applying namespaces to the classes themselves. If an element is a member of a visual component, every one of its sub-element classes should use the component’s base class name as a namespace.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/334/1*JtBu9c57LXekb2Hqiy11Tw.png" /></figure><p><strong>Namespacing</strong> your classes keeps your components self-contained and modular. It reduces the specificity needed to style child elements and reduces the probability of a conflict with an existing class.</p><p><strong>4- Extend components with modifier classes</strong></p><p>Create a modifier class to expand an existing component when it needs to look slightly different in a specific context.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/238/1*HXlV3P6TPpaeJ26eJkAZpw.png" /></figure><p>It has been already stated the downsides of modifying components based on one of their parent elements. but to restate: A modifier class can be used anywhere. Modifier classes can be used as many times as necessary. Finally, modifier classes show the developer’s purpose quite clearly in the HTML. Location-based classes, on the other hand, are totally invisible to a developer who is just looking at the HTML, raising the chances of it being missed.</p><p><strong>5- Use CSS Methodology</strong></p><p>By providing a class-based system for breaking up large web designs into several small, modular, discrete units, all CSS methodologies address the scalability and maintainability issue in CSS. Each UI module can be reused in a design and even ported from one project to the next if the CSS methodologies are the same.</p><p>CSS methodologies accomplish a lot more than just solving the CSS scalability problem. They make developing and iterating a design much simpler. They make it easier to read and understand front-end code, provide ready-made documentation, and enable multiple people to work on a design.</p><p>Most popular CSS methodologies are:</p><ul><li><a href="https://www.keycdn.com/blog/oocss">OOCSS (Object Oriented Css)</a></li><li><a href="https://en.bem.info/methodology/quick-start/">BEM (Block Element Modifier)</a></li><li><a href="http://smacss.com/">SMACSS (Scalable and Modular Architecture for CSS)</a></li><li><a href="https://www.xfive.co/blog/itcss-scalable-maintainable-css-architecture/#:~:text=ITCSS%20stands%20for%20Inverted%20Triangle,namespace%2C%20cascade%20and%20selectors%20specificity.">ITCSS (Inverted Scalable CSS)</a></li><li><a href="https://acss.io/">ATOMIC CSS</a></li></ul><p><strong>6- Use preprocessors</strong></p><p>CSS preprocessors are scripting languages that extend CSS’s standard functionality. They allow us to use variables, nesting, inheritance, mixins, functions, and mathematical operations in our CSS code. CSS preprocessors make it simple to automate repetitive tasks, and code bloat and errors, build reusable code snippets, and ensure backward compatibility.</p><p>Each CSS preprocessor has its own syntax, which it compiles into standard CSS so that it can be rendered on the client side by browsers. Currently, Sass, LESS, and Stylus are the three most common and reliable CSS preprocessors( There are many smaller ones as well). CSS preprocessors all perform almost same things, but in different ways and with different syntaxes.</p><p>Let’s investigate main features and functionalities LESS provides us.</p><ul><li>Variables</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*rqNSM9ITGUbEJ2ulQ2NWYw.png" /></figure><ul><li>Mixins</li></ul><p>Mixins are a way of including (“mixing in”) a bunch of properties from one rule-set into another rule-set.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/669/1*9yrgR5yzIgcIM3tFPZhdhQ.png" /></figure><p>The properties of the .bordered class will now appear in both #menu a and .post a.</p><ul><li>Nesting</li></ul><p>Less gives you the ability to use nesting instead of, or in combination with cascading.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*NkXELqcjZsV9Nh3TQsCC-w.png" /></figure><ul><li>Nested At-Rules and Bubbling</li></ul><p>At-rules such as @media or @supports can be nested in the same way as selectors. The at-rule is placed on top and relative order against other elements inside the same ruleset remains unchanged. This is called bubbling.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/433/1*VtdHdqv5YTmV468xXHL37w.png" /></figure><p>outputs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/1*T3IJCOgouv0ci4Y9Mzortw.png" /></figure><ul><li>Operations</li></ul><p>Arithmetical operations +, -, *, / can operate on any number, color or variable. If it is possible, mathematical operations take units into account and convert numbers before adding, subtracting or comparing them. The result has leftmost explicitly stated unit type. If the conversion is impossible or not meaningful, units are ignored. Example of impossible conversion: px to cm or rad to %.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*YYkVG-CY1jmmqqfM6MOPtQ.png" /></figure><p>Multiplication and division do not convert numbers. It would not be meaningful in most cases — a length multiplied by a length gives an area and css does not support specifying areas. Less will operate on numbers as they are and assign explicitly stated unit type to the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/1*cm860c9VOLwwJMDjoemkdw.png" /></figure><p>You can also do arithmetic on colors:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/453/1*EDhiZ-0KR1P_Kpon-5prKw.png" /></figure><p>You can check Less’s color functions in more details <a href="https://lesscss.org/functions/#color-operations">here</a></p><ul><li>Escaping</li></ul><p>Escaping allows you to use any arbitrary string as property or variable value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/291/1*i_KaDTaWRaTK2E6W1zyFFg.png" /></figure><p>results in:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/237/1*aSuwXF_DBVioVELt_moe8g.png" /></figure><ul><li>Functions</li></ul><p>Less provides a variety of functions which transform colors, manipulate strings and do maths. They are documented fully in the <a href="https://lesscss.org/functions/">function reference</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*bD_bFT2WdqztTSqcfXqtwg.png" /></figure><p><strong>SUMMARY</strong></p><p>CSS isn’t just for design. Just because you’re writing CSS doesn’t mean you should leave programming best practices. OOP, DRY, the open/closed principle, separation of concerns, and other concepts also apply to CSS.</p><p>Following best practices stated in this article will result in a reusable, scalable, and predictable CSS in your projects.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9dc6be77e70f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>