<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Isaac C.</title>
    <description>The latest articles on DEV Community by Isaac C. (@isaac).</description>
    <link>https://dev.to/isaac</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F165704%2F3b684103-f653-46b8-95a1-a818ce51d561.jpg</url>
      <title>DEV Community: Isaac C.</title>
      <link>https://dev.to/isaac</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/isaac"/>
    <language>en</language>
    <item>
      <title>Entering the Outro: Considerations on Evaluating the Kendrick v. Drake Rap Battle</title>
      <dc:creator>Isaac C.</dc:creator>
      <pubDate>Wed, 08 May 2024 12:22:25 +0000</pubDate>
      <link>https://dev.to/isaac/entering-the-outro-considerations-on-evaluating-kendrick-v-drake-ia2</link>
      <guid>https://dev.to/isaac/entering-the-outro-considerations-on-evaluating-kendrick-v-drake-ia2</guid>
      <description>&lt;h2&gt;
  
  
  Hip Hop History has been made
&lt;/h2&gt;

&lt;p&gt;Kendrick Lamar vs. Drake will go down as a historical moment in Hip Hop. Their rap battle is likely the peak of their shared history beginning with them collaborating, then (maybe) becoming friends, disagreeing with each other’s decisions, leading to years of numerous sneak dissing. When the moment came for them to battle, they each produced an impressive array of high quality diss records. They were already highly skilled, and grasping at legendary status. With this battle, their names in Hip Hop history are forever etched.&lt;/p&gt;

&lt;p&gt;Of course discussions on who won and who lost will go on for quite awhile. Some will vehemently believe it was Drake. For others it will undeniably be Kendrick. And others will never quite subscribe to a single winner. No matter the stance, discussions will continue.&lt;/p&gt;

&lt;p&gt;As such, there are some important considerations worth noting as we enter this rap battle’s epilogue.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Rap Battle
&lt;/h2&gt;

&lt;p&gt;First, we should confine our definition of rap battle. For the purposes of this article, we will restrict the discussion of rap battles to the public production of diss records/songs about another artist. We will only focus on cases where the artists are producing records to be consumed by the general public, often distributed by CD’s, radio, or streaming platforms.&lt;/p&gt;

&lt;p&gt;At the core of a rap battle, is answering one question, “If this rapper focused solely on rapping about/against that rapper, who wins?” That is it. A rap battle is competitive art, it is sport. Can you string together a plausible set of truths or analysis, given what you know and what information is out there about another person, and compose a better diss record? A more mild version of the rap battle is school-ground clowning. You are tasked with using observations, and creativity to compose a joke that’s undeniably funnier than your opponent in order to render them the (bigger) clown. It’s a game.&lt;/p&gt;

&lt;h2&gt;
  
  
  "Where's the proof"
&lt;/h2&gt;

&lt;p&gt;As funny as a “yo mama” joke may be, no one is actually asking for proof that when someone’s mother turns around, the earth has, in fact, spun on its axis. It’s a joke at the expense of another. Similarly, in the moment of the rap battle, proof is not a necessity. That doesn’t mean proof is not valuable. It can absolutely supercharge a bar, and even change the course of the battle, but in the moment of the battle, proof is not a primary consideration. The primary inquiry surrounds the question, “who has the better bars?”&lt;/p&gt;

&lt;p&gt;A rap battle is not investigative journaling over beats. Rappers are not required to collect information and produce documents, videos, books, and analysis on their opponent. A rap battle is not the forum for the presentation of that type of content. And although news or gossip may result from a rap battle, that production is not an obligation for the rapper, especially while competing. Their primary goal is to prove that they are the better rapper. The “receipts” can help, but they’re a secondary concern.&lt;/p&gt;

&lt;p&gt;A rap battle is also not a moral or ethical competition for its participants. Rappers are not tasked with explaining why their opponent is an evil, or worse person than they are. They can use that as a tactic to win, but it isn’t the place of a rap battle to evaluate who is the better member of society. That’s not what the competition was designed for. And the competitive arena of a rap battle, given the speed and general desire to win, is not capable of being a stable ground on which to discuss how moral or ethical a person is. A rap battle is a place to dismantle your opponent as quickly and artistically as you can, while also doing your best to ensure your reputation remains intact. It does not have the time or space to nurture a discussion on who is more moral or ethical. And to expect that a rapper will prove that they are the more moral or ethical person than their opponent is an undue burden. That does not mean the audience is precluded from that discussion. The audience participates in the event as a witness. They are not bound by the same time restrictions as the rappers (e.g. they can leave and come back and the battle will continue). The audience has the capacity to facilitate that discussion. But it is not a requirement for the rappers to bring up, or address their own, or their opponents proximity to morality. &lt;/p&gt;

&lt;h2&gt;
  
  
  "Pedo Allegations Were Too Far"
&lt;/h2&gt;

&lt;p&gt;Pedo(philia) allegations are serious, and one could absolutely make the argument that Kendrick took it to far to make those accusations. That is a worthy debate to have. At the same time, we should consider that even though there aren’t many rules in a rap battle, there are some. And among them, the most well-known rule is to not mention another person’s partners or children, and that if you do, every topic is available. Pusha T is among the recent artists to highlight this rule. &lt;a href="https://www.complex.com/music/a/cmplxtara-mahadevan/pusha-t-calls-breakfast-club-to-talk-drake-diss-story-of-adidon"&gt;Specifically, he (&lt;em&gt;Pusha T&lt;/em&gt;) stated that Drake’s mention of his partner, by name, is why he took their rap battle to the next level of disrespect&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Keeping in mind that a rap battle is a competitive sport, wherein proof is not required at the moment of the battle, a rapper only needs to make plausible claims. If there is some content, that could allow the audience to believe the claim, and the other artist has crossed the “line in the sand”, then the door is open to move in that direction. It doesn’t mean that the rapper has to, or even that they should, it only means that they can.&lt;/p&gt;

&lt;p&gt;Again, let’s be clear, pedo allegations are serious. They are not a joke (and especially if they’re made out of thin air) it should be avoided. Rappers do not have a license to blatantly lie, and they shouldn’t. They should be held accountable and called out whenever a line is crossed. But they are not journalists. And we are not in a court of law. Rappers are artists, and storytellers, and musicians. The product of their work has and will always have a fluid relationship with reality.&lt;/p&gt;

&lt;p&gt;I am not interested in definitively stating whether or not Kendrick took it too far, or even if Drake took it too far. Considering one of the core rules of rap battles, the proverbial gloves were removed early into the battle. And once the gloves are off, it’s not always easy to find exactly where they are placed.&lt;/p&gt;

&lt;h2&gt;
  
  
  "Kendrick was too hateful"
&lt;/h2&gt;

&lt;p&gt;A rap battle is a strategic endeavor. The term “battle” is not in the name simply to sound nice. It is a metaphorical battle. And in a battle, you typically want your opponent to believe you are are bigger, badder, more resourced, more prepared, and all around more ready and capable of easily dismantling and defeating them. You want them to fear you. Both Drake and Kendrick understand this, and they always have. Their early diss records, both “Push Ups”/“Taylor Made” and “Euphoria”/ “6:16 in LA” are littered with warnings, and reminders, that they are the best and that the other should not continue down the war path.&lt;/p&gt;

&lt;p&gt;None of us actually knows if Kendrick hates Drake. And to callback to the earlier point on the goal of the rap battle, it doesn’t really matter if he does or not. He really just needs Drake to believe it. The audience believing it is a bit of a bonus. He needs Drake to truly believe that he has a deep well of resentment, and anger to source his greatest rapping ability from. He needs Drake to believe that he is “the boogeyman”. Because if Drake believes that his opponent is not only skilled and maybe crazy, but also deeply hates him, then the dynamics of the battle have shifted. Kendrick will have mentally moved the board in his favor. Hate, in this case is an intimidation tactic first and foremost. The validity of Kendrick’s hate is a secondary matter.&lt;/p&gt;

&lt;h2&gt;
  
  
  "People just wanted to see Drake Lose"
&lt;/h2&gt;

&lt;p&gt;This may be true, some certainly feel this way, and some don’t, and some initially believed Kendrick was the underdog. It doesn’t help that very little of this is verified (and maybe even verifiable). Regardless, proving this is inconsequential. Drake and Kendrick are two of the most popular rappers of our generation. They can and have produced globally recognized, hit records, on multiple occasions. They can write a song, and a damn good one at that. They know it, we know it, and they consistently remind us. Each of them has repeatedly rapped that they are the greatest of all time, they are the King, and there is no other rapper above them (especially in their generation).&lt;/p&gt;

&lt;p&gt;Consequently, if statements like that are made, and there’s some data to back it up, as there is (e.g. sales, streaming, awards etc.), then as greats they can and are expected to overcome the audience’s predispositions. The craving for their loss is not a valid excuse. It is a reason why one person may have had more to overcome than the other, but it’s not enough of a significant hindrance, or a justifiable reason for why they, as the greatest to ever rap, lost.&lt;/p&gt;

&lt;p&gt;Even if the audience wanted to see Drake lose, he absolutely has the ability to make a record, so clearly good, that it has to be admitted as being such, even by his detractors. And if he is truly the best, and there is no question, then the desire to see him lose is only eligible for being a noticeable obstacle, it is not eligible for being the sole reason he lost.&lt;/p&gt;

&lt;h2&gt;
  
  
  "Drake is not a colonizer, they worked with him"
&lt;/h2&gt;

&lt;p&gt;This discussion has many layers to it. It intertwines thoughts on Blackness, colonialism, capitalism, and the global diaspora. This is probably the most complex topic to come from their rap battle and it is likely best kept in it’s own, separate article, where it can be treated with the proper time and care it deserves.&lt;/p&gt;

&lt;p&gt;What is worth addressing is the notion that the rappers he worked with benefitted from him, and therefore he can’t be a colonizer. Whether or not he is an actual colonizer is for another place. The worthy note to make is that there are forms of colonialism where the people being colonized are “benefitted” (it may even be considered a constituent element). Essentially, the colonized receive something they desire. The asterisk to that reception, is that whatever they receive will never equal or supersede what the colonizing entity receives. It is a (potentially very) uneven trade.&lt;/p&gt;

&lt;h2&gt;
  
  
  "__ won and that's it"
&lt;/h2&gt;

&lt;p&gt;Who won is going to be debated for quite a while. And there is no definitive “right” or “wrong” answer. Two people can view the same record multiple ways.&lt;/p&gt;

&lt;p&gt;The important aspect to remember is that you can change your mind. It’s okay. No matter what you think or feel today, you are able to reevaluate at any time. Receipts and evidence may come out that alters your original (maybe even public) assessment. That’s okay. It’s your thoughts on the winner of a rap battle, your opinion is not set in stone. You can absolutely revisit it.&lt;/p&gt;

&lt;p&gt;Drake and Kendrick remain highly skilled rappers. There is no question or change in the fact that they can write and perform a hit record. These are the two biggest artists of our time, who battled it out. The ending of the battle does not mean they are done.&lt;/p&gt;

&lt;p&gt;A rap battle, especially a good one, is a moment in time. It is the moment a pot boils. It’s hot, and dangerous to touch without being prepared and thinking it through. But as all things, it cools down, it ends. And we are tasked with returning to our lives, grateful that we were present for such a historical event.&lt;/p&gt;

</description>
      <category>hiphop</category>
      <category>kendricklamar</category>
      <category>drake</category>
      <category>rap</category>
    </item>
    <item>
      <title>A (Simple) Modal Management Option for React Native</title>
      <dc:creator>Isaac C.</dc:creator>
      <pubDate>Sat, 13 May 2023 12:23:06 +0000</pubDate>
      <link>https://dev.to/isaac/a-simple-modal-management-option-for-react-native-d3i</link>
      <guid>https://dev.to/isaac/a-simple-modal-management-option-for-react-native-d3i</guid>
      <description>&lt;h2&gt;
  
  
  We talking about modals
&lt;/h2&gt;

&lt;p&gt;Your basic modals aren't that difficult to build. For a simple modal, you'll want to be able to open it and close it. You'll probably use some form of &lt;code&gt;isVisible&lt;/code&gt; or &lt;code&gt;open&lt;/code&gt; prop set to true/false, and maybe some neat animations so that the modal slides/fades when it enters or exits the user's view. But the modal itself isn't the focus of this article. The focus is on how we manage those modals across the application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/3oEjI105rmEC22CJFK/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/3oEjI105rmEC22CJFK/giphy.gif" alt="allen-iverson-practice" width="480" height="478"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In my case, I joined a team, and we started this process of refactoring large portions of the application. And I realized that it might be beneficial to take this time and revisit and refactor the modal management logic. The logic worked, but it wasn't in a style we wanted to maintain. And after expressing this, it was agreed that I could refactor it.&lt;/p&gt;

&lt;p&gt;Originally, I wanted to adopt an approach that I had experienced in a previous role. But I couldn't remember the exact implementation details (maybe a sign that they were well-hidden hahaha).&lt;/p&gt;

&lt;p&gt;I did remember that we might have used some form of portal, and I considered doing the same. The problem is that React Native doesn't exactly support portals (out of the box), which is understandable. I could have (and probably easily) used a package and commenced, but we were in the middle of a major refactor and no one was thrilled to add a new package. So, I had to do this from scratch, only using native React Native tools.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Requirements
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/UtKQmptld4nXOTBBdQ/giphy-downsized-large.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/UtKQmptld4nXOTBBdQ/giphy-downsized-large.gif" alt="schitts-creek-required" width="480" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first thing we did was list our base-level requirements:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Context should handle the modal opening/closing&lt;/strong&gt; - Some form of context should hold the internal logic for how the modal is shown.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hook as an Interface&lt;/strong&gt; - Components should use a hook as an interface for opening a modal (i.e. the component shouldn't directly use the context)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pass Custom Data&lt;/strong&gt; - We should have the ability to pass data (we'll call props) to the hook and have those props be received by the rendered modal&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Support Custom and Default modals&lt;/strong&gt; - The consumer can pass/request their own custom modal if they need to. And if they don't specify a modal, a default modal is loaded and will be rendered with the props passed to it.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Those were the "Final 4" of our absolute needs. The bonuses would have been 5) Easy animation handling, and 6) Support for modal-in-modal (I know, this is bad hahaha but sometimes you're asked for it, and pushing back doesn't work 🤷🏾‍♂️). But we really just wanted something clear, and easy to use, that would last if we couldn't get around to refactoring it in the near future.&lt;/p&gt;

&lt;p&gt;And that's when I found &lt;a href="https://itnext.io/managing-modals-with-react-hooks-c9c55c458368"&gt;this article&lt;/a&gt; suggesting something similar to what we wanted. But, for us, it wasn't exactly what we wanted. And we opted not to &lt;em&gt;fully&lt;/em&gt; adopt it. But the overall approach was in the right direction. So we took the core pieces and made some slight modifications. And below is how that looked...&lt;/p&gt;




&lt;h2&gt;
  
  
  Building the Context
&lt;/h2&gt;

&lt;p&gt;First, we built the context&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createContext&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useCallback&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;DEFAULT_MODAL&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@components/CustomModal&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ModalContext&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createContext&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;DEFAULT_PROPS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;primaryCTA&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;secondaryCTA&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;shouldCenterTitle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;shouldShowClose&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ModalProvider&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;children&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;modalName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setModalName&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;modalProps&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setModalProps&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;DEFAULT_PROPS&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;openModal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;modalName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;mName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;DEFAULT_MODAL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;setModalName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nf"&gt;setModalProps&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;modalProps&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;closeModal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setModalName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;closeModal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;modalName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;modalProps&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;openModal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;ModalContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Provider&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;ModalContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Provider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ModalProvider&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ModalContext&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's review this. The context is storing 2 pieces of state and exposing 4 things: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The context stores the name of the modal. You can think of this a bit like a key in an object&lt;/li&gt;
&lt;li&gt;The context also stores the data that is intended to be passed to the modal, which we call &lt;code&gt;modalProps&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;And the 4 things this context exposes are: 
a) The ability to open the modal (by passing as an argument, the name of the modal, and the props intended to be passed to the modal)
b) The ability to close the modal (wherein the Context will remove the name)
c) The name of the modal set in state 
d) The props (object) to be passed to the modal&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Remember our (overall) goal was to get the 4 requirements listed above. And this context got us there. But it's not the only thing we would need.&lt;/p&gt;




&lt;h2&gt;
  
  
  Building the adjacent Hook
&lt;/h2&gt;

&lt;p&gt;The context was our core, but we didn't want everyone digging into that core directly. We wanted an interface, and that's where the hook came in. So we built this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useContext&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ModalContext&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@context/ModalContext&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;useModal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ModalContext&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;useModal must be used within a ModalProvider&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This hook is again, trying to be as simple as possible, it's really just returning the context, and only throwing an error if we're operating outside of the provider.&lt;/p&gt;




&lt;h2&gt;
  
  
  Adding the Provider to the App
&lt;/h2&gt;

&lt;p&gt;Speaking of the Provider, before we forget, let's be sure we have that setup. Here's what we did, and it should look familiar.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;CustomModal&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@components/CustomModal&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;ModalProvider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
       &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;CustomModal&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt; &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="cm"&gt;/** Continue reading (please)... **/&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
       &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;YOUR_OTHER_COMPONENTS_AND_PROVIDERS_ETC&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;ModalProvider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  The Actual Modal Component
&lt;/h2&gt;

&lt;p&gt;At this point, you might be asking, "Where in the world is the actual modal that gets rendered? I've seen ModalContext's that conditionally render the modal inside of it, where's your modal?" And you'd be 100% right to ask those questions. Here it is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useCallback&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;TransactionModal&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@modals/TransactionModal&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;FunUserModal&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@modals/FunUserModal&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useModal&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@hooks/useModal&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;DEFAULT_MODAL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;a string I like&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;FUN_MODAL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;another one of my favorite strings&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MODAL_LIST&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;DEFAULT_MODAL&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt; &lt;span class="nx"&gt;TransactionModal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;FUN_MODAL&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt; &lt;span class="nx"&gt;FunUserModal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;CustomModal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;closeModal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;modalName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;modalProps&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useModal&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;renderModal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useCallback&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;MODAL_LIST&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;modalName&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Component&lt;/span&gt;
        &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;modalProps&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        &lt;span class="na"&gt;closeModal&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;closeModal&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        &lt;span class="na"&gt;isOpen&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="o"&gt;!!&lt;/span&gt;&lt;span class="nx"&gt;modalName&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;closeModal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;modalName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;modalProps&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;modalName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;renderModal&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can read through this together. And we can start with, where is this getting rendered. This component is rendered in 1 place, in the App.js (as you've seen above), this gets rendered nowhere else. Let's review the section before the component, and then get into the actual component.&lt;/p&gt;

&lt;h3&gt;
  
  
  Checking out our own little "static store"
&lt;/h3&gt;

&lt;p&gt;At the top of this component, we have a simple key in the format below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;NAME_OF_MODAL_TO_BE_USED_EVERYWHERE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;string-that-will-only-be-used-as-the-value-of-the-key&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we have the object holding the location of the Modals, in the format below. You can think of this as a "static store" (i.e. it's not dynamic on its own, you have to add and remove components and change the keys manually). This object's keys are the above consts, and the key's values are the references to actual React components.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;LIST_OF_ALL_MODALS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;NAME_OF_MODAL_TO_BE_USED_EVERYWHERE&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt; &lt;span class="nx"&gt;ActualReactJSComponent&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Diving into the component
&lt;/h3&gt;

&lt;p&gt;Next, we have the actual component. At the top of the component, we are destructuring from the hook, the &lt;code&gt;modalName&lt;/code&gt;, the &lt;code&gt;modalProps&lt;/code&gt;, and the &lt;code&gt;closeModal&lt;/code&gt; function. All of these are stored within the ModalContext, and are made available to this component via the &lt;code&gt;useModal&lt;/code&gt; hook.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;CustomModal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;closeModal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;modalName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;modalProps&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useModal&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;renderModal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useCallback&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;MODAL_LIST&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;modalName&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Component&lt;/span&gt;
        &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;modalProps&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        &lt;span class="na"&gt;closeModal&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;closeModal&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        &lt;span class="na"&gt;isOpen&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="o"&gt;!!&lt;/span&gt;&lt;span class="nx"&gt;modalName&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;closeModal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;modalName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;modalProps&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;modalName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;renderModal&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we have a function (called &lt;code&gt;renderModal&lt;/code&gt;) that uses the modalName, by passing it as a key to the &lt;code&gt;MODAL_LIST&lt;/code&gt; object, and in turn receiving the React component (i.e. the modal). Once it has the component, it returns it, while spreading the &lt;code&gt;modalProps&lt;/code&gt; onto it, along with the &lt;code&gt;closeModal&lt;/code&gt; function, and coercing &lt;code&gt;modalName&lt;/code&gt; into a boolean which will determine when the modal should be opened. Meaning, if this function is called, it will return (and thereby render) a React component, or more specifically a modal (hence the name &lt;code&gt;renderModal&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Finally, if we attempt to render this component without a &lt;code&gt;modalName&lt;/code&gt;, it simply returns null. Otherwise, it calls the function, and the function returns the rendered component, thus rendering the modal.&lt;/p&gt;




&lt;h2&gt;
  
  
  How do we use this interface in our components?
&lt;/h2&gt;

&lt;p&gt;That's all well and good, but how do we use this? What does using this interface look like for the individual components? Well, there are 2 options:&lt;/p&gt;

&lt;h3&gt;
  
  
  Option A: Using the default modal
&lt;/h3&gt;

&lt;p&gt;If we just want to use the default modal (i.e. we don't want to have to build a new modal), we can do the below. We don't need to pass a name because the &lt;code&gt;openModal&lt;/code&gt; function has a default argument that sets the &lt;code&gt;modalName&lt;/code&gt; to the default modal. We pass only the props that we want to be passed to the modal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;openModal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;closeModal&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useModal&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;onPress&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;openModal&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Do you exist?&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Please confirm your existence&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;primaryCTA&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;backgroundColors&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;Colors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;myColorOne&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Colors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;myColorTwo&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
          &lt;span class="na"&gt;buttonTitle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Yes, I do&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;colors&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Colors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;black&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;onPress&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;You clicked the primary 'call to action' button&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
          &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="na"&gt;secondaryCTA&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;backgroundColors&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;Colors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;myColorThree&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Colors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;myColorFour&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
          &lt;span class="na"&gt;buttonTitle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;No, I don't&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;colors&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Colors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;black&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;onPress&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;closeModal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
       &lt;span class="p"&gt;},&lt;/span&gt;
     &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;View&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="cm"&gt;/** Component with some button that has the onPress prop **/&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;View&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Option B: Using a custom modal:
&lt;/h3&gt;

&lt;p&gt;If we don't want to use the default modal (i.e. we need to build a fully custom modal), we can use the &lt;code&gt;openModal&lt;/code&gt; function and pass the name of the modal, and the props we want to be spread onto it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;openModal&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useModal&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;onPress&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;openModal&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;modalName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;FUN_MODAL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;modalProps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;onDelete&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;deleteActionFunction&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;

 &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;View&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="cm"&gt;/** Component with some button that has the onPress prop **/&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;View&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  What are the Tradeoffs or Things to consider?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Without types, the props passed to the modal are quite loose - There's no type safety on the &lt;code&gt;modalProps&lt;/code&gt;. This means, almost anything can be added to that object. That's not necessarily the &lt;em&gt;worst&lt;/em&gt; thing (it &lt;em&gt;can&lt;/em&gt; maybe even be argued that it's a good thing). But on top of that, we're spreading the props, which has its own detriments. One of them is that you're not 100% sure &lt;em&gt;what's&lt;/em&gt; getting spread unless you investigate. If we were implementing this in TypeScript, I'd recommend using some form of generic so that the props object being passed to the hook is a bit clearer and more restrictive. Regardless, of whether or not you love/hate this "object freedom", it's worth keeping in mind.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We are using strings - This might be a bit of a nitpick, but for this use case, I'm not a big fan of using strings. In general string literals can easily be misspelled, accidentally changed, etc. Here, we alleviate some of this worry by using a const that holds the string literal. This allows us to rely on the import statement, as well as IntelliSense when we want to pass a &lt;code&gt;modalName&lt;/code&gt;. We are also using the &lt;code&gt;ALERT_LIST&lt;/code&gt; object's built-in key-value syntax to actually find the component. However, we do have to type the name of the key twice (i.e. once as a standalone const, and then again as the key in the object) but that's a price we were willing to pay.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We call it &lt;code&gt;modalProps&lt;/code&gt; and &lt;code&gt;modalName&lt;/code&gt; when we maybe could just call it &lt;code&gt;modal&lt;/code&gt; and &lt;code&gt;props&lt;/code&gt;, but we felt like &lt;code&gt;modal&lt;/code&gt; sounded a bit like a standalone component, and &lt;code&gt;props&lt;/code&gt; a tad too vague. Sure, the context of the names should help shed light on their meaning, and this is certainly more of a preference but we wanted a little bit more verbosity.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Speaking of names, &lt;code&gt;CustomModal&lt;/code&gt; &lt;em&gt;might&lt;/em&gt; be better named &lt;code&gt;ModalViewer&lt;/code&gt; or &lt;code&gt;ModalViewManager&lt;/code&gt;, since it's not &lt;em&gt;literally&lt;/em&gt; a modal, it only returns a modal. I'm (always) open to hearing better names and why they're better. But this was a bit of a nitpick for us as we had quite a significant amount of refactoring left. So we stuck with &lt;code&gt;CustomModal&lt;/code&gt; as our name and moved on.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;What happens when a string is passed that isn't represented by a component - This is a valid point and something we'll likely fix soon. We could throw an error when a matching component isn't found. In TypeScript, maybe some form of union of string literals could be helpful to use to restrict rogue strings from getting passed in. I'm not sure if an enum would make the most sense, but I'd be open to hearing why it might. Overall this is something to think about. And I might add, it could be a bit of a result of #2 (that using strings, in this manner, has tradeoffs).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Modal-in-Modals - I'm not sure this implementation can clearly and easily support opening a modal on top of another modal. But to be fair, supporting this ability was a bonus, not a requirement. It does technically give us a little ammo to push back on any modal-in-modal designs 😉 But since this wasn't a requirement for us, we're okay with not being able to support this.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Animation - This approach sort of precludes us from using the native Modal features/props that have to deal with opening and closing the modal. The rendering of the modal is fully controlled by the coercion of the &lt;code&gt;modalName&lt;/code&gt; to a boolean. Once it's false, the modal is no longer rendered, regardless of the animation props on it. We could make use of &lt;a href="https://reactnative.dev/docs/animations"&gt;React Native's Animated API&lt;/a&gt; to resolve this. But it's not the option built specifically for modals, and that made us a little sad. But animation was a bonus, not a requirement, so we're a little less sad.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It takes a second to see what's happening - We think this implementation is simple and clear. But that's a bit subjective. It's totally valid that coming into this, for the very first time, could be slightly jarring. That's part of why we opted for some of the naming verbosity. We thought it might help make the behavior clear.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I think it's worth noting that this list of Tradeoffs and Things to Consider is not exhaustive. As with everything (especially in software design), there are many tradeoffs. These are only the first few that kind of "poked us in the side". In the end, we deemed them acceptable in the short term. Some we'll get around to fixing soon (i.e. error handling, and animations), and others we'll live with. Are there more tradeoffs? Yes, most likely, but perfect doesn't exist, and for now (and for us) this implementation is good. &lt;/p&gt;




&lt;p&gt;&lt;a href="https://i.giphy.com/media/8fen5LSZcHQ5O/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/8fen5LSZcHQ5O/giphy.gif" alt="excellent-simpsons" width="496" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This implementation is very simple (at least it's intended to be). The file lengths are small, the names are verbose, and it can be quickly read, and improved by engineers at (just about) all levels. That's intentional. As much as we (currently) like this, this implementation is not meant to be used forever (at least for us). It's a placeholder structure that's simple and would be relatively easy for us to re-work the inner implementation details without having to destroy the components using the interface. We know in the future that:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We will probably want some form of Context that manages our modals&lt;/li&gt;
&lt;li&gt;We will probably want a hook that provides an interface to the Component for the context&lt;/li&gt;
&lt;li&gt;We will probably want to pass props that will be received by the rendered modal &lt;/li&gt;
&lt;li&gt;We will probably want a default component rendered if we don't pass one, and a custom component rendered if we do&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is &lt;em&gt;an&lt;/em&gt; option, there are many more with different tradeoffs to consider. But the above implementation gets all four of those items relatively well. Hopefully reading about this implementation helps you in your own modal management scheming, and/or inspires you to modify (this) and write about it for others to learn, discuss, and share.&lt;/p&gt;

</description>
      <category>react</category>
      <category>reactnative</category>
      <category>modal</category>
      <category>modals</category>
    </item>
  </channel>
</rss>
