<?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 Silvia Larasatul on Medium]]></title>
        <description><![CDATA[Stories by Silvia Larasatul on Medium]]></description>
        <link>https://medium.com/@silvialarasatul?source=rss-9bc8de761624------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qiApjDAPHz4UDFqr9kMPLQ.jpeg</url>
            <title>Stories by Silvia Larasatul on Medium</title>
            <link>https://medium.com/@silvialarasatul?source=rss-9bc8de761624------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 08:58:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@silvialarasatul/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[Why Collaboration is the New Competitive Advantage for Women in Tech?]]></title>
            <link>https://medium.com/@silvialarasatul/beyond-the-only-woman-in-the-room-why-collaboration-is-the-new-competitive-advantage-for-women-6c5d6ded56a4?source=rss-9bc8de761624------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c5d6ded56a4</guid>
            <category><![CDATA[career-advice]]></category>
            <category><![CDATA[self-development]]></category>
            <category><![CDATA[collaboration]]></category>
            <category><![CDATA[women-in-tech]]></category>
            <category><![CDATA[pyladies]]></category>
            <dc:creator><![CDATA[Silvia Larasatul]]></dc:creator>
            <pubDate>Fri, 26 Dec 2025 12:17:21 GMT</pubDate>
            <atom:updated>2025-12-26T12:21:23.647Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y-rehH7pFoFljfnDAvG4tQ.jpeg" /><figcaption><a href="https://www.pexels.com/photo/women-colleagues-gathered-inside-conference-room-1181622/">Photo by Christina Morillo</a></figcaption></figure><p>For many female professionals in the industry, the “Only Woman in the Room” syndrome is not merely an occasional inconvenience; it is a statistical reality.</p><p>Recent studies from the <strong>WomenTech Network’s 2025 report </strong>have revealed that <strong>only 42%</strong>, fewer than half of working-age women, are currently engaged in the global workforce<strong>.</strong> While emerging economies are witnessing an upward trajectory in female participation, advanced economies are experiencing stagnation, often hindered by insufficient policy support for workforce reentry. Even within the labor market, representation remains skewed; women constitute only 42% of the total labor pool, and their presence diminishes further in decision-making corridors, holding just <strong>31.7% of leadership positions.</strong></p><p>This systemic underrepresentation creates a heavy psychological burden: the pressure to represent one’s entire gender, the hesitation to voice dissent, and the fatigue of navigating environments not designed for inclusivity.</p><p>However, a paradigm shift is underway. For women in technology, networking and collaboration are transcending their reputation as mere “soft skills.” They are emerging as critical strategic assets — survival mechanisms essential for navigating a complex ecosystem. By synthesizing broad industry data with intimate insights from community leaders across the Asia region — specifically the recent <strong>Global PyLadies Conference Panel</strong> — it becomes evident that the most effective antidote to professional isolation is the intentional cultivation of community.</p><p>This is where the intervention of a professional network becomes transformative. In the Global PyLadies Conference panel discussion, it described the palpable unease of navigating male-dominated conferences — a silence that can feel deafening. Community dissolves this alienation. It provides essential validation, confirming that the hurdles faced, whether technical bottlenecks or unconscious bias, are often shared experiences rather than individual shortcomings. This collective understanding converts private doubt into resilience.</p><h3><strong>Psychological Safety as a Catalyst for Innovation</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*traODW_Q6TZR3n9bMGDULw.jpeg" /><figcaption><a href="https://www.pexels.com/photo/man-in-red-long-sleeve-shirt-and-blue-denim-jeans-standing-beside-woman-in-white-and-5711000/">Photo by Tima Miroshnichenko</a></figcaption></figure><p>There exists a pervasive misconception that “safe spaces” or women-centric groups are merely social enclaves. In reality, they function as high-performance incubators. Innovation, by definition, requires risk-taking. To propose novel architectures or debug complex systems, one must be willing to err. However, in environments lacking inclusivity, the social cost of making a mistake is disproportionately high for women.</p><p>Google’s landmark “Project Aristotle” study empirically demonstrated that the primary predictor of a high-performing team is <strong>psychological safety</strong> — the assurance that one will not face humiliation for speaking up.</p><p><strong>A representative from PyLadies Manila</strong> emphasized this imperative during the panel, noting that their primary objective was to cultivate an environment where women could “learn without judgment.” When the fear of scrutiny is removed, technical competency accelerates.</p><p><strong>A representative from PyLadies Yogyakarta</strong> provided a practical application of this philosophy. Recognizing that high-intensity technical meetups could be exclusionary to newcomers, she implemented “chill” events — informal gatherings that prioritized connection over competition. By lowering the barrier to entry, she fostered an environment of trust. In these psychologically safe zones, women are empowered to ask fundamental questions and take intellectual risks, thereby accelerating their professional development.</p><h3><strong>Collaboration Over Competition</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZD3zHVE7KQUtf4NhdbCGjg.jpeg" /><figcaption><a href="https://www.pexels.com/photo/group-of-people-watching-on-laptop-1595385/">Photo by Fox</a></figcaption></figure><p>In a technology industry often characterized by aggressive disruption and rapid scaling, women have historically been socialized to view professional advancement through a lens of scarcity. For decades, women felt pressured to guard their positions fiercely against peers. This “scarcity mindset” is damaging; it isolates talented individuals and creates a fractured ecosystem where energy is spent on horizontal rivalry rather than vertical growth. To survive and thrive in the modern tech landscape, women must actively dismantle this outdated construct and recognize that another woman’s success is not a threat to their own, but a proof of concept that widens the path for everyone.</p><p>Data from the AnitaB.org institute indicates that women with active mentorship are significantly more likely to remain in the tech industry than their isolated counterparts. The PyLadies panel offered a compelling case study of this retention mechanism in action. A representative from PyLadies Kuala Lumpur recounted her experience establishing a new chapter. Rather than succumbing to the pressure to prove her capability in isolation, she engaged in cross-border collaboration, soliciting advice from the Manila chapter.</p><p>Because the Manila team viewed her as an ally rather than a competitor, they shared their best practices and resources. This exchange of intellectual capital allowed the Kuala Lumpur chapter to bypass early operational pitfalls and accelerate their growth, effectively skipping the painful learning curve that usually accompanies a startup phase. It serves as a potent reminder: when women share knowledge — be it code, salary data, or leadership strategies — they elevate the baseline for the entire demographic.</p><p>Furthermore, this type of collaboration acts as a powerful antidote to the “imposter syndrome” that disproportionately affects underrepresented groups in tech. Competition often breeds silence; when everyone is a rival, admitting to a gap in knowledge feels like a weakness. In contrast, a collaborative culture normalizes the learning process. It creates spaces where women can admit uncertainty and receive guidance rather than judgment. This mentorship dynamic — whether peer-to-peer or top-down — accelerates skill acquisition. It transforms the professional journey from a solitary climb up a steep ladder into a collective expedition where team members pull each other up.</p><p>Ultimately, the choice between collaboration and competition is a choice between stagnation and evolution. The challenges facing the technology sector today — from ethical AI governance to cybersecurity — are too complex for any single individual to solve in isolation. By prioritizing partnership, women are not just being “nice”; they are being strategic. They are building resilient, interconnected webs of influence that are far harder to dismantle than any solitary career. When women choose to amplify each other’s voices and validate each other’s expertise, they do more than just advance individual careers; they fundamentally reshape the culture of technology into one that values contribution over conquest.</p><h3><strong>From Invisible to Visible Impact</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*veQm07-v1fnWV3MiIOZ83Q.jpeg" /><figcaption><a href="https://www.pexels.com/photo/wavy-haired-woman-holding-a-megaphone-7859937/">Photo by cottonbro studio</a></figcaption></figure><p>Ultimately, the most profound argument for collaboration is that it is the most effective engine for career visibility. Within a collaborative network, visibility becomes a shared project. This is the strategy of <strong>“amplification”</strong>: when one woman voices an idea or achieves a milestone, her network echoes it, credits her, and ensures the wider organization takes notice. By validating each other’s contributions in meetings and public forums, women can ensure that their expertise is not just utilized, but celebrated.</p><p>This collaborative amplification transforms a career from a series of solitary tasks into a portfolio of recognized impact. Being a “highlight” in the industry happens when a professional is buoyed by a network of sponsors who speak her name when she isn’t in the room. When women collaborate — whether by co-authoring technical papers, co-organizing community events like the PyLadies summits, or simply cross-referencing each other’s work on social platforms — they create a “surround sound” effect for their personal brands. This does not dilute their individual achievements; rather, it provides the social proof that leadership often looks for when assigning high-profile projects or promotions.</p><p>Moreover, collaboration enhances the quality of the work itself, making it more likely to stand out. In the complex ecosystem of modern tech, the most groundbreaking solutions — from ethical AI frameworks to decentralized financial systems — are rarely the product of a single mind. They are born from the friction and fusion of diverse perspectives. A woman who isolates herself limits her output to her own existing knowledge base. Conversely, a woman who collaborates actively absorbs the best practices, shortcuts, and innovative thinking of her peers. Her work becomes sharper, more robust, and more innovative. Therefore, collaboration is not just a safety net; it is a spotlight. It allows women to deliver superior results and ensures that those results are seen, recognized, and rewarded, turning steady competence into a standout career.</p><p>Proficiency in collaboration positions women as indispensable architects of organizational culture, effectively fast-tracking them into leadership roles. In an era where technical silos frequently stifle progress, the ability to bridge the gap between engineering, product design, and business strategy is a rare and highly valued competency. Women who actively cultivate collaborative networks tend to develop a systemic view of the organization; they understand how distinct functions intersect and influence one another. This “connective intelligence” allows them to solve problems that are invisible to those working in isolation. By becoming the central nodes of information exchange, these women naturally gravitate toward the center of decision-making processes. Consequently, they are not merely seen as individual contributors who execute tasks, but as strategic leaders who mobilize teams.</p><p>The commitment to collaboration fundamentally redefines the concept of professional legacy. For a woman in technology, being a “highlight” is not solely defined by the code she ships or the products she launches, but by the doors she holds open for others. When successful women leverage their influence to mentor junior talent or advocate for inclusive hiring practices, they generate a multiplier effect that extends far beyond their own tenure. This stewardship ensures that their impact is durable; it transforms their individual success from a statistical anomaly into a replicable standard. By prioritizing the collective over the individual, women do not just navigate the current landscape of the technology industry — they actively reconstruct it, ensuring that the next generation inherits a field defined not by scarcity and isolation, but by abundance and possibility.</p><p><strong>The Multiplier Effect on Innovation</strong> Finally, this shift toward a collaborative ethos does more than sustain individual careers; it fundamentally improves the technology being built. The most complex challenges of our time — from bias in algorithmic decision-making to the ethical deployment of AI — cannot be solved in an echo chamber. When women collaborate across borders and disciplines, they bring a multiplicity of perspectives that identify blind spots often missed by homogenous teams. By fostering an environment where inquiry is encouraged and knowledge is fluid, collaborative networks ensure that the products of the future are not just faster or more efficient, but more equitable and robust. In this way, the “collaborative advantage” becomes a competitive advantage for the entire digital economy.</p><h3>Diversity as a Technical Asset</h3><p>This shift toward a collaborative ethos does more than sustain individual careers. It fundamentally improves the architecture of the technology itself. The most complex challenges of our time — from mitigating bias in algorithmic decision-making to ensuring the ethical deployment of Artificial Intelligence — cannot be solved in an echo chamber. When women collaborate across borders, disciplines, and backgrounds, they bring a multiplicity of perspectives that identify blind spots often missed by homogenous teams. A solution that appears robust to a team of engineers with identical life experiences may fail catastrophically when introduced to a diverse user base. By fostering an environment where inquiry is encouraged and knowledge is fluid, collaborative networks act as a rigorous form of quality assurance, ensuring that the products of the future are not just faster, but more equitable and robust.</p><p>Furthermore, collaboration acts as an accelerant for problem-solving. In a siloed model, an engineer might spend weeks attempting to optimize a specific data pipeline, unaware that a peer in a different department or a different country has already solved that precise issue. Collaborative ecosystems dismantle these inefficiencies. By normalizing the sharing of “works in progress” rather than just finished products, women in tech can leverage the collective intelligence of the group to bypass standard hurdles. This “open-source” approach to professional problem-solving allows teams to iterate with greater speed and precision, shifting energy from reinventing the wheel to designing entirely new vehicles for progress.</p><p>In this way, the “collaborative advantage” evolves into a competitive advantage for the entire digital economy. We are moving into an era where technology is no longer just a tool, but a pervasive infrastructure that governs healthcare, finance, and communication. The risks of getting it wrong are high. Collaborative networks ensure that this infrastructure is built with a wide-lens view, anticipating consequences and designing for inclusivity from the ground up. Therefore, when women prioritize connection, they are not just networking; they are future-proofing the industry, ensuring that the systems we build today remain relevant and beneficial for the diverse world of tomorrow.</p><h3>Conclusion</h3><p>The technological landscape is characterized by volatility; languages evolve, frameworks become obsolete, and tools change. in such a fluid environment, technical acumen is necessary, but a robust professional network is indispensable.</p><p>In the final analysis, the trajectory of a woman’s career in technology is no longer solely determined by her individual technical acuity. As the industry accelerates into an era defined by rapid disruption and increasing complexity, the most durable competitive advantage is a robust, collaborative network. True innovation, resilience, and leadership are now the byproducts of connection, not isolation. When we amplify one another’s voices, share our intellectual capital, and build bridges across borders, we dismantle the structural barriers that have historically defined the field. The future of technology will not be shaped by those who climb alone, but by those who lift others as they rise. It is time to build a reality of collective power, ensuring that the path forward is wide enough for all of us to walk together.</p><p>Thanks! 🙌</p><p>Follow <a href="https://www.instagram.com/pyladies.yk/">@pyladies.yk</a> and <a href="https://www.instagram.com/pyladies_global/">@pyladies_global</a> (instagram) to meet women in tech community</p><h3><strong>References:</strong></h3><ul><li><a href="https://www.womentech.net/women-in-tech-stats"><em>WomenTech Network. “Women in Tech Stats 2025.”</em></a></li><li><a href="https://www.youtube.com/watch?v=Cs7VoZWdJEg"><em>PyLadies APAC Panel Discussion (2024). “Python Across Asia: Collaboration and Cross-Border Support.”</em></a></li><li><a href="https://rework.withgoogle.com/intl/en/guides/understanding-team-effectiveness"><em>Google re:Work. “Project Aristotle: Understanding Team Effectiveness.”</em></a></li><li><a href="https://www.google.com/search?q=https://anitab.org/research-and-impact/top-companies/"><em>AnitaB.org. “Retention of Women in the Technical Workforce.”</em></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c5d6ded56a4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Hooks: React.memo, useCallback, dan useMemo]]></title>
            <link>https://medium.com/@silvialarasatul/react-hooks-react-memo-usecallback-dan-usememo-b0131f14bf2d?source=rss-9bc8de761624------2</link>
            <guid isPermaLink="false">https://medium.com/p/b0131f14bf2d</guid>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[usememo]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Silvia Larasatul]]></dc:creator>
            <pubDate>Tue, 15 Mar 2022 15:40:01 GMT</pubDate>
            <atom:updated>2022-03-15T15:40:01.246Z</atom:updated>
            <content:encoded><![CDATA[<h3>React.memo</h3><p><strong><em>React.memo</em></strong> merupakan <em>Higher-order component</em> yang tidak melakukan rendering ulang komponen jika <em>props</em> tidak berubah. <strong><em>React.memo</em></strong> memungkinkan untuk <strong><em>memoize </em></strong>(menyimpan output dari <em>function</em> sebelumnya) komponen berdasarkan <em>props</em> miliknya. Caranya adalah dengan membungkus komponen ke dalam <strong><em>React.memo()</em></strong>.</p><p>Pada JavaScript terdapat variabel yang bisa menyimpan satu dari dua tipe data, yaitu nilai <strong><em>primitive </em></strong>atau nilai <strong><em>reference</em></strong>. Perbedaannya, yang membandingkan nilai <strong><em>primitive</em></strong> adalah nilai dari masing-masing variabel. Sedangkan nilai <strong><em>reference</em></strong> dibandingkan dengan lokasi nilai masing-masing variabel di memori (referensi).</p><blockquote>export default React.memo(NthFib)</blockquote><blockquote>export default React.memo(NthPrime)</blockquote><blockquote>&lt;NthFib<br> count={fibCount}<br> increment={() =&gt; setFibCount(© =&gt; c + 1)}<br>/&gt;</blockquote><blockquote>&lt;NthPrime<br> count={primeCount}<br> increment={() =&gt; setPrimeCount(© =&gt; c + 1)}<br>/&gt;</blockquote><p>Untuk dapat menghindari <em>rendering</em> ulang komponen ketika props tidak berubah adalah dengan membandingkan kedua <strong><em>count</em></strong> <em>props</em> (pada <em>code</em> di atas) dan mengabaikan increment props karena function memiliki nilai reference. Sehingga hasilnya sebagai berikut:</p><blockquote>export default React.memo(NthFib, (prevProps, nextProps) =&gt; {<br> return prevProps.count === nextProps.count<br>})</blockquote><blockquote>export default React.memo(NthPrime, (prevProps, nextProps) =&gt; {<br> return prevProps.count === nextProps.count<br>})</blockquote><p>Namun, untuk mempertahankan <em>reference </em>dari <strong><em>increment</em></strong> <em>props</em> di seluruh render memerlukan <strong><em>useCallback</em></strong>.</p><h3>useCallback</h3><p><strong><em>useCallback </em></strong>mengembalikan <em>memoize callback </em>di mana <em>function </em>apapun yang dibuat dengan <strong><em>useCallback </em></strong>tidak akan dibuat ulang pada re-<em>rendering</em> berikutnya atau dipertahankan selama <em>rendering</em>. Ini akan mengambil dua argumen, yaitu <em>function</em> dan <em>array</em>. <em>Memoized function</em> yang dikembalikannya hanya akan berubah jika salah satu nilai dalam <em>dependency array</em> berubah.</p><p><strong><em>useCallback</em> </strong>dapat membuat satu<em> function</em> pada render awal dan menggunakannya kembali pada render berikutnya. Dengan adanya <strong><em>useCallback</em></strong>, ketika <em>React.memo</em> membandingkan <strong><em>increment</em></strong> <em>prop</em> sebelumnya dengan<strong> <em>increment</em></strong> <em>prop</em> baru, referensi akan sama dan operator (===) akan bekerja seperti yang diharapkan.</p><p>Berikut <em>code</em>-nya:</p><blockquote>export default React.memo(NthFib)</blockquote><blockquote>export default React.memo(NthPrime)</blockquote><blockquote>function App() {<br> const [fibCount, setFibCount] = React.useState(1)<br> const [primeCount, setPrimeCount] = React.useState(1)</blockquote><blockquote>const handleReset = () =&gt; {<br> setFibCount(1)<br> setPrimeCount(1)<br> }</blockquote><blockquote>const add10 = () =&gt; {<br> setFibCount(© =&gt; c + 10)<br> setPrimeCount(© =&gt; c + 10)<br> }</blockquote><blockquote>const incrementFib = React.useCallback(() =&gt;<br> setFibCount(© =&gt; c + 1),<br> []<br> )</blockquote><blockquote>const incrementPrime = React.useCallback(() =&gt;<br> setPrimeCount(© =&gt; c + 1),<br> []<br> )</blockquote><blockquote>return (<br> &lt;React.Fragment&gt;<br> &lt;button onClick={add10}&gt;Add 10&lt;/button&gt;<br> &lt;button onClick={handleReset}&gt;Reset&lt;/button&gt;<br> &lt;hr /&gt;<br> &lt;NthFib<br> count={fibCount}<br> increment={incrementFib}<br> /&gt;<br> &lt;hr /&gt;<br> &lt;NthPrime<br> count={primeCount}<br> increment={incrementPrime}<br> /&gt;<br> &lt;/React.Fragment&gt;<br> );<br>}</blockquote><h3>useMemo</h3><p><strong><em>useMemo </em></strong>mengembalikan <em>memoized value</em>. Dengan <strong><em>useMemo</em></strong>, kita bisa <em>memoize expensive calculation</em>.</p><p><strong><em>useMemo</em></strong> mengambil dua argumen, yaitu <em>function</em> dan <em>array</em>. Ini akan mengembalikan nilai yang akan dihitung pada render awal dan kapan pun salah satu nilai dalam <em>array</em> berubah. Contoh <em>code</em>-nya sebagai berikut:</p><blockquote>const memoizedValue = useMemo(() =&gt; {<br> return computeExpensiveValue(a, b);<br>}, [a, b]);</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b0131f14bf2d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Hooks: useRef]]></title>
            <link>https://medium.com/@silvialarasatul/react-hooks-useref-22c651db1e52?source=rss-9bc8de761624------2</link>
            <guid isPermaLink="false">https://medium.com/p/22c651db1e52</guid>
            <category><![CDATA[react-hook-usereducer]]></category>
            <category><![CDATA[react-hook]]></category>
            <dc:creator><![CDATA[Silvia Larasatul]]></dc:creator>
            <pubDate>Mon, 14 Mar 2022 17:08:24 GMT</pubDate>
            <atom:updated>2022-03-14T17:08:24.475Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>useRef</em></strong> berfungsi untuk mempertahankan nilai di seluruh <em>render </em>tanpa menyebabkan <em>re-render</em>.</p><blockquote>function Counter() {<br> const [count, setCount] = React.useState(0)<br> const id = React.useRef(null)</blockquote><blockquote>const clearInterval = () =&gt; {<br> window.clearInterval(id.current)<br> }</blockquote><blockquote>React.useEffect(() =&gt; {<br> id.current = window.setInterval(() =&gt; {<br> setCount(c =&gt; c + 1)<br> }, 1000)</blockquote><blockquote>return clearInterval<br> }, [])</blockquote><blockquote>return (<br> &lt;div&gt;<br> &lt;h1&gt;{count}&lt;/h1&gt;<br> &lt;button onClick={clearInterval}&gt;Stop&lt;/button&gt;<br> &lt;/div&gt;<br> )<br>}</blockquote><p>Pada <em>code</em> di atas, <strong><em>useRef </em></strong>menerima <em>initial value</em> sebagai argumen pertama dan mengembalikan objek yang memiliki properti <strong><em>current</em></strong>. Apapun yang ditambahkan ke <strong><em>current</em></strong> akan dipertahankan di semua <em>render</em>. Jika nilai dari <strong><em>useRef </em></strong>diteruskan sebagai <em>ref prop</em> pada elemen React apapun, React akan mengatur properti<strong><em> current </em></strong>ke DOM <em>node</em> yang sesuai. Ini memungkinkan <strong><em>useRef </em></strong>untuk mengambil nilai <em>input </em>atau mengatur fokus.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22c651db1e52" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Hooks: useReducer]]></title>
            <link>https://medium.com/@silvialarasatul/react-hooks-usereducer-a449dddf2a53?source=rss-9bc8de761624------2</link>
            <guid isPermaLink="false">https://medium.com/p/a449dddf2a53</guid>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[usereducer]]></category>
            <category><![CDATA[react-hook-usereducer]]></category>
            <dc:creator><![CDATA[Silvia Larasatul]]></dc:creator>
            <pubDate>Mon, 14 Mar 2022 14:52:33 GMT</pubDate>
            <atom:updated>2022-03-14T14:52:33.782Z</atom:updated>
            <content:encoded><![CDATA[<h3>Reduce</h3><p><em>Reduce</em> adalah pola <em>functional programming</em> yang mengambil <em>collection</em> (seperti <em>array </em>atau <em>object</em>) sebagai <em>input </em>dan mengembalikan nilai tunggal sebagai <em>output</em>.</p><p><em>Reduce</em> mampu melacak akumulasi <em>state</em> secara internal tanpa memodifikasi <em>state </em>di luar cakupannya sendiri. Caranya, setiap elemen dalam collection memanggil fungsi <em>reducer</em> dengan meneruskan dua argumen, akumulasi <em>state</em> dan <em>element</em> yang ada di <em>collection</em>. Yang dikembalikan oleh fungsi <em>reducer</em> akan diteruskan sebagai argumen pertama ke pemanggilan <em>reducer</em> berikutnya dan menghasilkan nilai akhir.</p><p>Contoh <em>code</em>-nya:</p><blockquote>const nums = [2, 4, 6];<br>const initialState = 0;</blockquote><blockquote>function reducer(state, value) {<br> return state + value;<br>}</blockquote><blockquote>const total = nums.reduce(reducer, initialState);</blockquote><p>Pada code di atas perubahan state dan value yang terjadi adalah sebagai berikut:</p><p><strong>Value awal</strong>: 0</p><p><strong>Pemanggilan pertama</strong>:<br>state: 0<br>value: 2</p><p><strong>Pemanggilan kedua</strong>:<br>state: 2<br>value: 4</p><p><strong>Pemanggilan ketiga</strong>:<br>state: 6<br>value: 6</p><h3>useReducer</h3><p><strong><em>useReducer </em></strong>memungkinkan untuk menambah <em>state</em> ke komponen fungsi dan mengelola <em>state</em> menggunakan pola <em>reducer</em>. <strong><em>useReducer</em></strong> dapat mengembalikan <em>array</em> dengan elemen pertama menjadi <em>state</em> dan elemen kedua menjadi fungsi <em>dispatch</em> yang ketika dipanggil, akan memanggil <em>reducer</em>.</p><p>Ketika <strong><em>useReducer </em></strong>dipanggil, apapun yang diteruskan ke <em>dispatch</em> akan diteruskan sebagai argumen kedua (<em>value</em>) ke <em>reducer</em>. Argumen pertama akan diteruskan secara implisit oleh React dan akan menjadi nilai <em>state</em> sebelumnya.</p><p>Berikut contoh <em>code</em>-nya:</p><blockquote>function reducer(state, value) {<br> return state + value;<br>}</blockquote><blockquote>function Counter() {<br> const [count, dispatch] = React.useReducer(reducer, 0);</blockquote><blockquote>return (<br> &lt;React.Fragment&gt;<br> &lt;h1&gt;{count}&lt;/h1&gt;<br> &lt;button onClick={() =&gt; dispatch(1)}&gt;+&lt;/button&gt;<br> &lt;/React.Fragment&gt;<br> );<br>}</blockquote><p>Pada <em>code </em>di atas, setiap kali <em>button</em> diklik, <em>dispatch</em> akan dipanggil. Kemudian dispatch akan memanggil <em>reducer </em>dan meneruskannya ke dua argumen. Dari <em>code </em>di atas, apabila ditambahkan <em>action</em> lain, seperti kurang dan <em>reset</em>, menjadi:</p><blockquote>function reducer(state, action) {<br> if (action === “increment”) {<br> return state + 1;<br> } else if (action === “decrement”) {<br> return state — 1;<br> } else if (action === “reset”) {<br> return 0;<br> } else {<br> throw new Error(`This action type isn’t supported.`);<br> }<br>}</blockquote><blockquote>function Counter() {<br> const [count, dispatch] = React.useReducer(reducer, 0);</blockquote><blockquote>return (<br> &lt;React.Fragment&gt;<br> &lt;h1&gt;{count}&lt;/h1&gt;<br> &lt;button onClick={() =&gt; dispatch(“increment”)}&gt;+&lt;/button&gt;<br> &lt;button onClick={() =&gt; dispatch(“decrement”)}&gt;-&lt;/button&gt;<br> &lt;button onClick={() =&gt; dispatch(“reset”)}&gt;Reset&lt;/button&gt;<br> &lt;/React.Fragment&gt;<br> );<br>}</blockquote><h3>useState dan useReducer</h3><p><strong><em>useState</em></strong> dan <strong><em>useReducer</em></strong> sama-sama dapat menambah <em>state</em> ke komponen fungsi. <strong><em>useReducer </em></strong>memberikan lebih banyak fleksibilitas karena memungkinkan untuk memisahkan <em>state</em> yang diperbarui dari tindakan yang memicu <em>update</em>.</p><p><strong><em>useState</em></strong> sebaiknya digunakan ketika ada <em>state</em> yang berbeda diperbarui secara independen dari satu sama lain (seperti <em>hovering, selected</em>, dsb.). <strong><em>useReducer </em></strong>sebaiknya digunakan jika <em>state</em> cenderung diperbarui secara bersamaan atau jika memperbarui satu <em>state</em> harus didasarkan pada state lain.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a449dddf2a53" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Hooks: Custom Hooks]]></title>
            <link>https://medium.com/@silvialarasatul/react-hooks-custom-hooks-f3f65b9a0f75?source=rss-9bc8de761624------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3f65b9a0f75</guid>
            <category><![CDATA[custom-hook]]></category>
            <dc:creator><![CDATA[Silvia Larasatul]]></dc:creator>
            <pubDate>Mon, 14 Mar 2022 10:48:40 GMT</pubDate>
            <atom:updated>2022-03-14T10:48:40.536Z</atom:updated>
            <content:encoded><![CDATA[<h3>Aturan Hooks</h3><p>Hooks hanya dapat dipanggi dari tingkat teratas suatu komponen fungsi atau custom hook. Hooks tidak dapat dipanggil di tempat lain. Alasannya karena React bergantung pada urutan panggilan Hooks untuk melacak <em>internal state</em> dan referensi. Jika Hooks tidak dipanggil secara konsisten pada urutan yang sama di seluruh <em>render</em>, React tidak dapat menjalankannya.</p><h3>Membuat Hover</h3><p>Untuk membuat <em>hover</em> pada aplikasi dapat menggunakan <strong><em>onMouseOver</em></strong> dan <strong><em>onMouseOut</em></strong>. Ketika <em>hovering</em>, <strong><em>onMouseOver</em></strong> dipanggil dan ketika tidak <em>hovering</em>, <strong><em>onMouseOut</em></strong> dipanggil. Berikut contoh <em>code</em> menggunakan <strong><em>useState</em></strong> hook.</p><blockquote>function Info({ id, size }) {<br> const [hovering, setHovering] = React.useState(false);</blockquote><blockquote>const mouseOver = () =&gt; setHovering(true);<br> const mouseOut = () =&gt; setHovering(false);</blockquote><blockquote>return (<br> &lt;div className=”container”&gt;<br> {hovering === true ? &lt;Tooltip id={id} /&gt; : null}<br> &lt;svg<br> onMouseOver={mouseOver}<br> onMouseOut={mouseOut}<br> width={size}<br> viewBox=”0 0 16 16&quot;<br> &gt;<br> &lt;path d=”M9 8a1 1 0 0 0–1–1H5.5a1 1 0 1 0 0 2H7v4a1 1 0 0 0 2 0zM4 0h8a4 4 0 0 1 4 4v8a4 4 0 0 1–4 4H4a4 4 0 0 1–4–4V4a4 4 0 0 1 4–4zm4 5.5a1.5 1.5 0 1 0 0–3 1.5 1.5 0 0 0 0 3z” /&gt;<br> &lt;/svg&gt;<br> &lt;/div&gt;<br> );<br>}</blockquote><p><em>Code</em> di atas sudah bisa melakukan <em>hovering</em>. Namun, ketika ingin membuat fungsi lain yang membutuhkan <em>hovering</em>, nanti akan terjadi duplikasi. Solusinya adalah menggunakan <strong>Higher-order Components</strong> dan <strong>Render Props</strong>.</p><h4>Higher-order Components</h4><p>Dengan Higher-order Components, bisa membuat fungsi yang memanfaatkan komponen sebagai argumen. Dari fungsi tersebut dapat merangkum <em>logic</em> sendiri, kemudian merender komponen yang diteruskan. Dari sini, semua data dapat diteruskan ke komponen yang dirender melalui <em>props</em>. Jika membutuhkan <em>hovering</em> lagi, tinggal meneruskan komponen sebagai argumen ke fungsi tadi. Berikut contoh <em>code</em>-nya:</p><blockquote>function withHover(Component) {<br> return function (props) {<br> const [hovering, setHovering] = React.useState(false);</blockquote><blockquote>const mouseOver = () =&gt; setHovering(true);<br> const mouseOut = () =&gt; setHovering(false);</blockquote><blockquote>return (<br> &lt;div onMouseOver={mouseOver} onMouseOut={mouseOut}&gt;<br> &lt;Component {…props} hovering={hovering} /&gt;<br> &lt;/div&gt;<br> );<br> };<br>}</blockquote><blockquote>const InfoWithHover = withHover(Info);<br>const TrendChartWithHover = withHover(TrendChart);<br>const DailyChartWithHover = withHover(DailyChart);</blockquote><h4>Render Props</h4><p>Render props dapat meneruskan fungsi sebagai <em>props </em>ke komponen React, sehingga dapat merangkum shared <em>logic</em> di dalam komponen. Kemudian, untuk mengeluarkan data dari komponen tersebut, komponen akan diteruskan sebagai argumen ke<em> prop render</em>.</p><p>Berikut contoh <em>code</em>-nya:</p><blockquote>function Hover({ render }) {<br> const [hovering, setHovering] = React.useState(false);</blockquote><blockquote>const mouseOver = () =&gt; setHovering(true);<br> const mouseOut = () =&gt; setHovering(false);</blockquote><blockquote>return (<br> &lt;div onMouseOver={mouseOver} onMouseOut={mouseOut}&gt;<br> {render(hovering)}<br> &lt;/div&gt;<br> );<br>}</blockquote><blockquote>&lt;Hover render={(hovering) =&gt; &lt;Info hovering={hovering} /&gt;} /&gt;<br>&lt;Hover render={(hovering) =&gt; &lt;TrendChart hovering={hovering} /&gt;} /&gt;<br>&lt;Hover render={(hovering) =&gt; &lt;DailyChart hovering={hovering} /&gt;} /&gt;</blockquote><h3>Custom Hooks</h3><p>Untuk membuat <em>custom hooks</em> adalah dengan membuat fungsi yang diawali <strong><em>use</em></strong>. Dengan <em>custom hook</em>, apabila membutuhkan <em>hover </em>lagi, bisa memanggil <strong><em>useHover</em></strong> yang sudah didefinisikan sebelumnya. Berikut contoh <em>code</em>-nya:</p><blockquote>function useHover () {<br> const [hovering, setHovering] = React.useState(false)</blockquote><blockquote>const mouseOver = () =&gt; setHovering(true)<br> const mouseOut = () =&gt; setHovering(false)</blockquote><blockquote>const attrs = {<br> onMouseOver: mouseOver,<br> onMouseOut: mouseOut<br> }</blockquote><blockquote>return [hovering, attrs]<br>}</blockquote><blockquote>function Info ({ id, size }) {<br> const [hovering, attrs] = useHover()</blockquote><blockquote>return (<br> &lt;React.Fragment&gt;<br> {hovering === true<br> ? &lt;Tooltip id={id} /&gt;<br> : null}<br> &lt;svg<br> {…attrs}<br> width={size}<br> viewBox=”0 0 16 16&quot; &gt;<br> &lt;path d=”M9 8a1 1 0 0 0–1–1H5.5a1 1 0 1 0 0 2H7v4a1 1 0 0 0 2 0zM4 0h8a4 4 0 0 1 4 4v8a4 4 0 0 1–4 4H4a4 4 0 0 1–4–4V4a4 4 0 0 1 4–4zm4 5.5a1.5 1.5 0 1 0 0–3 1.5 1.5 0 0 0 0 3z” /&gt;<br> &lt;/svg&gt;<br> &lt;/React.Fragment&gt;<br> )<br>}</blockquote><p>Sekian rangkuman custom hooks. Semoga bermanfaat.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3f65b9a0f75" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Apa itu Execution Context dan React Hooks: useEffect?]]></title>
            <link>https://medium.com/@silvialarasatul/apa-itu-execution-context-dan-react-hooks-useeffect-25de4dd2cbcb?source=rss-9bc8de761624------2</link>
            <guid isPermaLink="false">https://medium.com/p/25de4dd2cbcb</guid>
            <dc:creator><![CDATA[Silvia Larasatul]]></dc:creator>
            <pubDate>Sun, 13 Mar 2022 16:31:27 GMT</pubDate>
            <atom:updated>2022-03-13T16:31:27.832Z</atom:updated>
            <content:encoded><![CDATA[<h3>Execution Context</h3><p>Bagian-bagian yang berasal dari pemecahan <em>code</em> disebut <em>execution context</em>. <em>Execution context</em> memungkinkan JavaScript untuk mengelola kompleksitas interpretasi, kemudian menjalankan <em>code</em>. <em>Execution context </em>yang pertama dibuat ketika JavaScript menjalankan <em>code</em> adalah <strong><em>Global Execution Context</em></strong>. <em>Execution context</em> terdiri dari objek global dan variabel bernama this. Setiap <em>execution context</em> memiliki dua fase terpisah, <strong><em>fase Creation</em></strong> dan <strong><em>fase Execution</em></strong>.</p><p>Pada fase <strong><em>Global Creation</em></strong>, JavaScript:</p><p>1. Membuat objek global.<br>2. Membuat objek “this”.<br>3. Mengatur ruang memori untuk variabel dan function.<br>4. Menetapkan deklarasi variabel <em>default value</em> “undefined” sambil menempatkan deklarasi<em> function</em> apapun di memori.</p><p>Fase <strong><em>Execution</em></strong> ketika JavaScript menjalankan code dari baris awal sampai terakhir dan memberikan <em>real value</em> ke variabel yang sudah ada di memori.</p><h3>React Hooks: useEffect</h3><p>Untuk memaksimalkan prediktabilitas pada program perlu meminimalkan <em>side effect</em> (semua hal yang berinteraksi di luar local function yang dijalankan), sehingga program bisa <em>bug-free </em>(bebas bug).</p><p><strong><em>useEffect </em></strong>memungkinkan melakukan <em>side effects</em> di <em>function</em>. <em>Function</em> menentukan <em>side effects</em> mana yang harus dijalankannya dan <em>array</em> menentukan kapan harus menjalankan kembali <em>effect</em> tersebut. Kapanpun program ingin menjalankan<em> side effect </em>tertentu, seperti membuat <em>network request</em>, memperbarui DOM, atau lainnya bisa menggunakan <strong><em>useEffect</em></strong>.</p><p><strong>Aspek <em>useEffect</em> adalah sebagai berikut:</strong></p><p><strong>1. Menambahkan effect</strong><br> <br>Untuk menambahkan <em>effect </em>ke React component, <strong><em>useEffect </em></strong>dipanggil dengan memberikan <strong><em>function</em></strong> yang mendefinisikan <strong><em>side effect</em></strong>. Setiap render, <em>effect</em> tidak akan berjalan sampai React memperbarui DOM dan <em>browser</em> telah menampilkan pembaruan, sehingga <em>side effect</em> tidak memblokir pembaruan ke UI.</p><p><strong>2. Melewatkan side effect</strong></p><p>Apabila meneruskan argumen kedua ke <strong><em>useEffect</em></strong>, <em>array</em> dari semua nilai luar perlu diteruskan ke argumen tersebut.<em> Effect</em> tidak bergantung pada nilai luar apapun, sehingga melewatkan array kosong sebagai argumen kedua akan aman dan <em>effect</em> hanya akan dipanggil pada render awal.</p><blockquote>function Profile () {<br> const [profile, setProfile] = React.useState(null)</blockquote><blockquote>React.useEffect(() =&gt; {<br> getGithubProfile(‘tylermcginnis’)<br> .then(setProfile)<br> }, [])</blockquote><blockquote>if (profile === null) {<br> return &lt;p&gt;Loading…&lt;/p&gt;<br> }</blockquote><blockquote>return (<br> &lt;React.Fragment&gt;<br> &lt;h1&gt;@{profile.login}&lt;/h1&gt;<br> &lt;img<br> src={profile.avatar_url}<br> alt={`Avatar for ${profile.login}`}<br> /&gt;<br> &lt;p&gt;{profile.bio}&lt;/p&gt;<br> &lt;/React.Fragment&gt;<br> );<br>}</blockquote><p>Pada code di atas, <em>username</em> ditambahkan di dalam <em>effect</em> di mana sama dengan memperkenalkan nilai luar ke <em>effect</em> tersebut. Sehingga <em>array</em> kosong harus dihapus atau memperbarui <em>array</em> dengan apa yang bergantung pada <em>effect</em>. Sehingga akan menjadi seperti ini:</p><blockquote>React.useEffect(() =&gt; {<br> getGithubProfile(username)<br> .then(setProfile)<br> }, [username])</blockquote><p><strong>3. Menghapus side effect</strong></p><p><em>Subscription</em> harus dihapus ketika komponen dihapus dari DOM atau ketika tidak lagi menerima <em>update</em> dari API, sehingga memori tidak akan bocor. Untuk melakukannya adalah dengan membuat <em>cleanup function</em>. Ketika mengembalikan <em>function</em> dari <strong><em>useEffect</em></strong>, React akan memastikan function dipanggil sebelum komponen dihapus dari DOM. Jika komponen dirender ulang, <em>cleanup function</em> dari <em>effect render</em> sebelumnya akan dipanggil sebelum memanggil ulang <em>effect</em> baru.</p><p>Berikut contoh code-nya:</p><blockquote>import { subscribe, unsubscribe } from ‘./api’</blockquote><blockquote>function Profile ({ username }) {<br> const [profile, setProfile] = React.useState(null)</blockquote><blockquote>React.useEffect(() =&gt; {<br> subscribe(username, setProfile)</blockquote><blockquote>return () =&gt; {<br> unsubscribe(username)<br> setProfile(null)<br> }<br> }, [username])</blockquote><blockquote>if (profile === null) {<br> return &lt;p&gt;Loading…&lt;/p&gt;<br> }</blockquote><blockquote>return (<br> &lt;React.Fragment&gt;<br> &lt;h1&gt;@{profile.login}&lt;/h1&gt;<br> &lt;img<br> src={profile.avatar_url}<br> alt={`Avatar for ${profile.login}`}<br> /&gt;<br> &lt;p&gt;{profile.bio}&lt;/p&gt;<br> &lt;/React.Fragment&gt;<br> );<br>}</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25de4dd2cbcb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React: useState]]></title>
            <link>https://medium.com/@silvialarasatul/react-usestate-b41aae8258c9?source=rss-9bc8de761624------2</link>
            <guid isPermaLink="false">https://medium.com/p/b41aae8258c9</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-hook]]></category>
            <dc:creator><![CDATA[Silvia Larasatul]]></dc:creator>
            <pubDate>Sat, 12 Mar 2022 17:39:17 GMT</pubDate>
            <atom:updated>2022-03-12T17:39:17.298Z</atom:updated>
            <content:encoded><![CDATA[<h3>useState</h3><p>useState dapat diakses dengan <strong><em>React.useState</em></strong>. useState menerima argumen tunggal, yaitu initial value untuk state tersebut dan mengembalikan array dengan item pertama menjadi bagian dari state dan item kedua menjadi function untuk memperbarui state tersebut.</p><p>Contoh code:</p><blockquote>function Theme() {<br> const [theme, setTheme] = React.useState(“light”);</blockquote><blockquote>const toDark = () =&gt; setTheme(“dark”);<br> const toLight = () =&gt; setTheme(“light”);</blockquote><blockquote>return (<br> &lt;div className={theme}&gt;<br> {theme === “light” ? (<br> &lt;button onClick={toDark}&gt;🔦&lt;/button&gt;<br> ) : (<br> &lt;button onClick={toLight}&gt;💡&lt;/button&gt;<br> )}<br> &lt;/div&gt;<br> );<br>}</blockquote><h3>The Mental Model</h3><p>useState memungkinkan untuk memicu re-render komponen, dan dapat mempertahankan nilai di antara renders.</p><h4>Trigger Re-render</h4><p>Setiap kali memanggil fungsi updater yang useState berikan, dengan nilai state yang berbeda dari saat ini, React akan melakukan re-render ke komponen dan memperbarui UI.</p><h4>Pertahankan Nilai</h4><p>useState dapat mempertahankan nilai di antara render function untuk mencegahnya dari pengumpulan sampah setelah function selesai dijalankan dan untuk memicu re-render komponen.</p><h3>Perbedaan useState dengan setState</h3><p>Pertama, tidak ada lagi instance wide API untuk memperbarui semua state komponen seperti yang ada pada setState. Tapi, setiap bagian state memiliki updater function sendiri. Kedua, tidak ada instance wide API untuk menyetel initial value dari semua properti state pada komponen. Sebagai gantinya, setiap bagian dari state memiliki pemanggilan useState sendiri.</p><p>setState akan melakukan pembaruan dengan menggabungkan dua objek state untuk membentuk state baru, sedangkan useState mengganti objek state sepenuhnya dengan state baru.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b41aae8258c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kenapa React Hooks?]]></title>
            <link>https://medium.com/@silvialarasatul/kenapa-react-hooks-e6cc67a10b31?source=rss-9bc8de761624------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6cc67a10b31</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react-hook]]></category>
            <dc:creator><![CDATA[Silvia Larasatul]]></dc:creator>
            <pubDate>Sat, 12 Mar 2022 16:14:19 GMT</pubDate>
            <atom:updated>2022-03-12T16:22:20.591Z</atom:updated>
            <content:encoded><![CDATA[<h3>React Hooks</h3><p>Pada versi terbaru React, kita tidak lagi menggunakan <strong><em>class</em></strong> atau <strong><em>this</em></strong>, sehingga diperlukan cara baru untuk menambahkan dan mengelola state di dalam komponen, yaitu melalui metode <strong><em>useState</em></strong>.</p><p><strong><em>useState </em></strong>menerima argumen tunggal, <em>initial value</em> untuk <em>state </em>dan mengembalikan <em>array</em> dengan item pertama menjadi bagian dari <em>state</em> dan item kedua menjadi <em>function</em> untuk memperbarui <em>state </em>tersebut.</p><h3>Component Lifecycle</h3><p>Tujuan akhir dari <em>lifecycle</em> selalu sinkronisasi. Sinkronisasi ini memungkinkan untuk mengelompokkan bagian-bagian logika yang terkait. Pada React Hooks terdapat <strong><em>useEffect</em></strong>. <strong><em>useEffect</em></strong> memungkinkan melakukan <em>side effects</em> di <em>function</em>. <em>Function</em> menentukan <em>side effects</em> mana yang harus dijalannya dan <em>array</em> menentukan kapan harus menjalankan kembali <em>effect</em> tersebut.</p><h3>Sharing non-visual Logic</h3><p>React tidak dapat melakukan <em>sharing non-visual logic</em> karena React memasangkan UI ke komponen. Hal ini menyebabkan adanya pola rumit seperti <strong>Higher-order Component</strong> dan <strong>Render Props</strong>. React Hooks memungkinkan untuk membuat <em>custom hook </em>yang dapat dipisahkan dari UI apapun. Caranya adalah dengan membuat custom <strong><em>useRepos</em></strong>. Hook akan mengambil <strong><em>id</em></strong> dari <strong><em>Repos</em></strong> yang ingin kita ambil dan akan mengembalikan <em>array</em> dengan item pertama menjadi status pemuatan dan item kedua menjadi <strong><em>repos</em></strong><em> state</em>.</p><p>Dengan adanya React Hooks akan memudahkan dalam pengaturan state, melakukan sinkronisasi tanpa Component Lifecycle, membuat custom hook yang terpisah dari UI, dsb.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6cc67a10b31" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React: Pemecahan Code (Code Splitting)]]></title>
            <link>https://medium.com/@silvialarasatul/react-pemecahan-code-code-splitting-1d4ff960d411?source=rss-9bc8de761624------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d4ff960d411</guid>
            <dc:creator><![CDATA[Silvia Larasatul]]></dc:creator>
            <pubDate>Sat, 12 Mar 2022 15:00:12 GMT</pubDate>
            <atom:updated>2022-03-12T15:00:12.807Z</atom:updated>
            <content:encoded><![CDATA[<h3>Code Splitting</h3><p>Pengguna tidak perlu mengunduh seluruh aplikasi ketika yang digunakan hanya sebagian. Untuk itu diperlukan pemecahan code (<em>code splitting</em>) yang dapat mengunduh <em>code</em> ketika diperlukan saja. Ada beberapa tools yang bisa digunakan, seperti <strong>Webpack </strong>dan <strong>ECMAScript <em>dynamic import</em></strong>. Pada <em>code splitting</em> ini akan menggunakan <em>dynamic import</em>.</p><p>Pada <strong>ES Modules</strong> impor modul tidak dapat dilakukan secara dinamis berdasarkan beberapa kondisi (karena bersifat <em>static</em>). Impor perlu dideklarasikan di bagian atas file. Oleh karena itu, dengan menggunakan <em>dynamic import</em>, modul tertentu dapat dimuat sesuai permintaan.</p><blockquote>if (editPost === true) {<br> import * as edit from “./editpost”;</blockquote><blockquote>edit.showEditor();<br>}</blockquote><p>Pada <em>code</em> di atas, <strong><em>editpost</em></strong> berisi <em>text editor</em> yang cukup besar. <em>Code</em> di atas juga menunjukkan bahwa <strong><em>editpost</em></strong> tidak akan diunduh sampai pengguna benar-benar siap menggunakannya.</p><h4>Mengimpor Modul Secara Dinamis</h4><blockquote>const Settings = (props) =&gt; (<br> &lt;DynamicImport load={() =&gt; import(“./Settings”)}&gt;<br> {(Component) =&gt;<br> Component === null ? &lt;Loading /&gt; : &lt;Component {…props} /&gt;<br> }<br> &lt;/DynamicImport&gt;<br>);</blockquote><p>Pada code di atas, <strong><em>DynamicImport</em></strong> akan menerima <em>load prop</em> yang ketika dipanggil otomatis mengimpor modul secara dinamis. Kemudian akan menerima fungsi sebagai <em>children</em> yang perlu dipanggil dengan modul yang diimpor.</p><p>Berikutnya, untuk membuat komponen <strong><em>DynamicImport</em></strong>, yang pertama memanggil <strong><em>props.load</em></strong>. Ini akan mengembalikan bahwa ketika <em>resolve</em>, harus memiliki modul. Setelah memiliki modulnya, membuat <em>re-render</em> dengan menambahkan modul yang diimpor secara dinamis ke <em>local state</em> sehingga dapat memanggil <strong><em>props.children</em></strong> dengan meneruskan modul tersebut.</p><p>Berikut <em>code</em>-nya:</p><blockquote>class DynamicImport extends React.Component {<br> state = {<br> component: null<br> }<br> componentDidMount() {<br> this.props.load()<br> .then((component) =&gt; {<br> this.setState({<br> component: component.default<br> ? component.default<br> : component<br> })<br> })<br> }<br> render() {<br> return this.props.children(this.state.component)<br> }<br>}</blockquote><p>Berikutnya menggunakan <strong><em>React.lazy</em></strong>. Dengan <strong><em>React.lazy</em></strong> memungkinkan untuk merender <em>dynamic import</em>. Selain itu, jika menggunakan <strong><em>React Suspense</em></strong> akan memberikan <em>prop fallback</em> untuk menampilkan sesuatu ketika modul dimuat. <em>Code</em>-nya sebagai berikut:</p><blockquote>const Settings = React.lazy(() =&gt; import(“./Settings”));</blockquote><blockquote>function App() {<br> return (<br> &lt;div&gt;<br> &lt;React.Suspense fallback={&lt;Loading /&gt;}&gt;<br> &lt;Settings /&gt;<br> &lt;/React.Suspense&gt;<br> &lt;/div&gt;<br> );<br>}</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d4ff960d411" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Class Fields]]></title>
            <link>https://medium.com/@silvialarasatul/class-fields-fb11d232dc8e?source=rss-9bc8de761624------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb11d232dc8e</guid>
            <dc:creator><![CDATA[Silvia Larasatul]]></dc:creator>
            <pubDate>Fri, 11 Mar 2022 16:16:43 GMT</pubDate>
            <atom:updated>2022-03-11T16:16:43.558Z</atom:updated>
            <content:encoded><![CDATA[<h3>Class Fields</h3><p><em>Class Fields</em> memungkinkan untuk menambah properti <em>instance</em> di <em>class</em> tanpa harus menggunakan metode <em>constructor</em>. Selain itu, <em>class field </em>dapat mendefinisikan variabel <em>state</em> secara langsung sebagai properti di <em>class</em>.</p><p>Berikut contoh <em>code</em>-nya:</p><blockquote>class PlayerInput extends Component {<br> state = {<br> username: ‘’<br> }<br> constructor(props) {<br> super(props)</blockquote><blockquote>this.handleChange = this.handleChange.bind(this)<br> }<br> handleChange(event) {<br> this.setState({<br> username: event.target.value<br> })<br> }<br> render() {<br> …<br> }<br>}</blockquote><blockquote>PlayerInput.propTypes = {<br> id: PropTypes.string.isRequired,<br> label: PropTypes.string.isRequired,<br> onSubmit: PropTypes.func.isRequired,<br>}</blockquote><blockquote>PlayerInput.defaultProps = {<br> label: ‘Username’,<br>}</blockquote><h4>Bagaimana menambahkan static method ke class dengan keyword static?</h4><p>Berdasarkan spesifikasi ES6 <em>class</em>, <em>static </em>hanya berfungsi dengan metode, bukan nilai. Oleh karena itu, pada kode di atas perlu ditambahkan <strong><em>propTypes</em></strong> dan <strong><em>defaultProps</em></strong> ke <strong><em>PlayerInput</em></strong> setelah mendefinisikannya dan bukan di <em>class body</em>. Jadi, alih-alih hanya mendefinisikan <em>static method</em> di <em>class body</em>, nilai <em>static</em> juga dapat didefinisikan, sehingga <strong><em>propTypes</em></strong> dan <strong><em>defaultProps</em></strong> dapat dipindahkan ke <em>class</em>. Berikut hasil penambahan <em>static method</em> pada <em>code</em>-nya:</p><blockquote>class PlayerInput extends Component {<br> static propTypes = {<br> id: PropTypes.string.isRequired,<br> label: PropTypes.string.isRequired,<br> onSubmit: PropTypes.func.isRequired,<br> }<br> static defaultProps = {<br> label: ‘Username’<br> }<br> state = {<br> username: ‘’<br> }<br> handleChange = (event) =&gt; {<br> this.setState({<br> username: event.target.value<br> })<br> }<br> render() {<br> …<br> }<br>}</blockquote><p>Ketika menambahkan <em>method</em> ke <em>class</em> sama seperti menambahkan <em>method</em> ke prototipe <em>function</em>. Ketika menggunakan <em>Class Fields</em>, untuk setiap <em>instance</em> yang dibuat, semua <em>method</em> akan dibuat ulang di memori. Berikut contoh <em>code</em>-nya:</p><blockquote>class Animal {<br> eat() {}<br>}</blockquote><blockquote>// Is equivalent to</blockquote><blockquote>function Animal() {}<br>Animal.prototype.eat = function () {};</blockquote><h3>Private Fields</h3><p>Aspek lain dari <em>Class Fields</em> adalah <em>Private Class</em>. <em>Private Class</em> digunakan apabila tidak ingin setiap <em>instance</em> mengakses <em>body</em> di dalam <em>class</em> tersebut. Pada <em>Class Fields</em>, untuk membuat <em>private fields</em> adalah dengan menggunakan <strong><em>‘#’</em></strong>. Berikut contoh <em>code</em>-nya:</p><blockquote>class Car {<br> #milesDriven = 0;<br> drive(distance) {<br> #milesDriven += distance;<br> }<br> getMilesDriven() {<br> return #milesDriven;<br> }<br>}</blockquote><blockquote>const tesla = new Car();<br>tesla.drive(10);<br>tesla.getMilesDriven(); // 10<br>tesla.#milesDriven; // Invalid</blockquote><p>Sekian rangkuman mengenai Class Fields.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb11d232dc8e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>