<?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: Mohamed Eltohamy</title>
    <description>The latest articles on DEV Community by Mohamed Eltohamy (@imcitizen13).</description>
    <link>https://dev.to/imcitizen13</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1053879%2Ffe204c42-f304-4cbe-af92-42361f28e30e.jpg</url>
      <title>DEV Community: Mohamed Eltohamy</title>
      <link>https://dev.to/imcitizen13</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/imcitizen13"/>
    <language>en</language>
    <item>
      <title>Fibonacci grid in React</title>
      <dc:creator>Mohamed Eltohamy</dc:creator>
      <pubDate>Fri, 19 Jun 2026 10:04:22 +0000</pubDate>
      <link>https://dev.to/imcitizen13/fibonacci-grid-in-react-4poe</link>
      <guid>https://dev.to/imcitizen13/fibonacci-grid-in-react-4poe</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F59jzcftywl3j1vfh0340.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F59jzcftywl3j1vfh0340.png" alt="Leonardo Fibonacci Color and Seashell with fibonacci sequence overlay" width="799" height="363"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Goal
&lt;/h2&gt;

&lt;p&gt;I want to create a &lt;strong&gt;Fibonacci&lt;/strong&gt; grid pattern component in &lt;strong&gt;React&lt;/strong&gt; that can the user can use and add elements to in any orientation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbmvc752l6e94eoey2oiv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbmvc752l6e94eoey2oiv.png" alt="Fibonacci View" width="800" height="492"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  React Component ⚛️
&lt;/h2&gt;

&lt;p&gt;I started by creating a React Component called /code &lt;strong&gt;FibonacciGrid&lt;/strong&gt;, and then added a couple of states.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Orientation&lt;/em&gt; is an enum that is either &lt;strong&gt;horizontal&lt;/strong&gt; or &lt;strong&gt;vertical.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;nBoxes&lt;/em&gt; for specifying the number of boxes/elements in the grid &lt;em&gt;(It should be a multiple of 3)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;elementResolution&lt;/em&gt; which holds the width and height of the grid specified by the user.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc26upfz3t2bshpgzu2cl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc26upfz3t2bshpgzu2cl.png" alt="Component basic code structure" width="799" height="290"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Grid vs Flex Layouts
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Grid layout&lt;/strong&gt; was my initial choice when I got started with this as it’s called &lt;strong&gt;FibonacciGrid&lt;/strong&gt; after all and a grid looks like it’ll be the obvious choice right? … well wrong because for the design that I made, I only needed to worry about 3 elements (Probably could’ve been done easily by grid but I already did something like it with &lt;em&gt;flex&lt;/em&gt; and I love ❤️ &lt;em&gt;flex&lt;/em&gt;. So flex is a go; here’s the orientation that I’m aiming for: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi8o5ans5oa41gt2gffay.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi8o5ans5oa41gt2gffay.png" alt="Grid vs Flex Layouts desired view" width="800" height="479"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I’m going to nest this layout in itself as you can see here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fujxx73bjgz4953f0i71n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fujxx73bjgz4953f0i71n.png" alt="Recursive Fibonacci view" width="800" height="481"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can see how it keeps nesting a new FibView, yeah I’m calling that now. Getting back to what's at hand, if the user sets the number of views/boxes to more than 3 then we’ll have to nest another view and repeat the process.&lt;/p&gt;

&lt;h2&gt;
  
  
  Design
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb4dd3ojlqxusp9ei3kyo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb4dd3ojlqxusp9ei3kyo.png" alt="Initial design" width="800" height="492"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I made this &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpz4el85qx57ofls01bdi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpz4el85qx57ofls01bdi.png" alt="Output" width="800" height="414"&gt;&lt;/a&gt;   &lt;/p&gt;

&lt;h2&gt;
  
  
  Orientation Wars
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fug75cvniqmm1h11ju70a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fug75cvniqmm1h11ju70a.png" alt=" " width="800" height="460"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Making the view have one behavior is simple enough, but now I need to make it dynamic.&lt;/p&gt;

&lt;p&gt;I set up a lot of variables and this function changes the variables on orientation change….&lt;/p&gt;

&lt;p&gt;And it worked, for the horizontal view, but not for the Vertical (as expected 🤪).&lt;/p&gt;

&lt;p&gt;Here’s how it looked:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6vvwz26f4xs2vx1bg9dq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6vvwz26f4xs2vx1bg9dq.png" alt="How the thing looks" width="800" height="568"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and that's even after I applied a little bit of React Wizardry.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdnexnkcpgo5odj7dsylv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdnexnkcpgo5odj7dsylv.png" alt="Orientation " width="799" height="388"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;if so then add it to the bottom of the flex row direction, ah yeah I did that too, now I change the &lt;em&gt;flex-direction&lt;/em&gt; depending on the orientation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Need to fix the vertical orientation issue
&lt;/h2&gt;

&lt;p&gt;OMG!!! So I was adding the 1 view to the same flex that contains the other two views, so I ended up with the 3 views with a 37% height and that was the issue.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reverse/Flip Orientations
&lt;/h2&gt;

&lt;p&gt;Vertical reverse and horizontal reverse, &lt;/p&gt;

&lt;p&gt;The end result should be like the one on the figure on the left, after changing a few things I set up the view to change the size to a fixed width and height based on its orientation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcw7zzut7l1g1hglbbo3c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcw7zzut7l1g1hglbbo3c.png" alt=" " width="800" height="460"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For some reason, I got the following figures on the right, not the same but close. Now starts the game of trial and error.&lt;/p&gt;

&lt;h3&gt;
  
  
  HorizontalReverse
&lt;/h3&gt;

&lt;p&gt;That was an easy one, I just needed to add one line to the condition that adds the large view to the end.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{(orientation === OrientationEnum.vertical ||
        orientation === OrientationEnum.horizontalReverse) &amp;amp;&amp;amp; (
        &amp;lt;div
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;onto the next one…&lt;/p&gt;

&lt;h3&gt;
  
  
  VerticalReverse
&lt;/h3&gt;

&lt;p&gt;Now &lt;/p&gt;

&lt;h2&gt;
  
  
  Orientation Expansion
&lt;/h2&gt;

&lt;p&gt;So as I was figuring out what to do I noticed that I missed a couple of orientations 4 to be exact. I was contemplating whether to implement them now or not as they’ll add an extra level of complexity, knowing me I just had to do it. This btw was a side project of a side project soooooo… let’s get into it. &lt;/p&gt;

&lt;p&gt;I went and added the extra orientations and worked out a nifty new way to figure it all out.&lt;/p&gt;

&lt;h3&gt;
  
  
  Flip (the nifty way)
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8h5760bz0g0nglkmiady.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8h5760bz0g0nglkmiady.png" alt="Flip variable" width="799" height="385"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now it’s getting complicated, but don’t worry I think I figured a way to simplify things.&lt;br&gt;
I added a new variable &lt;em&gt;flip&lt;/em&gt; which will just vertically flip all of the original 4 orientations, you can ask me why don’t I make flip-horizontal and flip-vertical, and to that, I say shhhh, not now but that is the future plan. (Something for another day).&lt;/p&gt;

&lt;p&gt;I leave this here as there is something more important that I need to do.&lt;/p&gt;
&lt;h2&gt;
  
  
  Important Change
&lt;/h2&gt;

&lt;p&gt;As of now most of the views are working well, I thought there should be some style added to them.&lt;/p&gt;

&lt;p&gt;I went and downloaded a couple of beautiful images from &lt;a href="https://unsplash.com/photos/a-colorful-mural-on-the-side-of-a-building-3PBKAHfEkxA?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt; from these amazing artists, check their work in the links below.&lt;/p&gt;

&lt;p&gt;Photos by &lt;a href="https://unsplash.com/@freguesiadeestrela?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Freguesia de Estrela&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/a-colorful-mural-on-the-side-of-a-building-3PBKAHfEkxA?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Photo by &lt;a href="https://unsplash.com/@fakurian" rel="noopener noreferrer"&gt;Milad Fakurian&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/a-colorful-mural-on-the-side-of-a-building-3PBKAHfEkxA?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Photo by &lt;a href="https://unsplash.com/@danieljschwarz" rel="noopener noreferrer"&gt;Daniel J. SchwarzHire&lt;/a&gt; on &lt;/p&gt;

&lt;p&gt;Photo by &lt;a href="https://unsplash.com/@neom" rel="noopener noreferrer"&gt;NEOM&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/a-colorful-mural-on-the-side-of-a-building-3PBKAHfEkxA?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Photo by &lt;a href="https://unsplash.com/@marekpiwnicki" rel="noopener noreferrer"&gt;Marek Piwnicki&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/a-colorful-mural-on-the-side-of-a-building-3PBKAHfEkxA?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;OK, let’s address the elephant in the room (🦣&amp;nbsp;me)&amp;nbsp;not you 🐘&amp;nbsp;yeah you, seriously though we need to now add children to the FibView. I’m now faced with a choice either to implement adding children to the view which is the whole point of this or add the images in the fibview itself, hmmmm.. Well as you know by now I usually take the harder route and give up midway, but that’s what what we’re gonna do right now.&lt;/p&gt;

&lt;p&gt;So as I never did this before I jumped into React’s docs and I think it’s gonna be something like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;FibView&amp;gt; 
    &amp;lt;img src="1.png"&amp;gt;&amp;lt;/img&amp;gt;
    &amp;lt;img src="2.png"&amp;gt;&amp;lt;/img&amp;gt;
    &amp;lt;img src="3.png"&amp;gt;&amp;lt;/img&amp;gt;
    &amp;lt;img src="4.png"&amp;gt;&amp;lt;/img&amp;gt;
    &amp;lt;img src="5.png"&amp;gt;&amp;lt;/img&amp;gt;
&amp;lt;/FibView&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then in the view we’ll get the children just like what we do with ContextProviders, so something like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SomeContextProvider(props: PropsWithChildren) {
...
    {props.children}
...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And after a little digging, it is actually the way, you gotta love modular systems.&lt;/p&gt;

&lt;p&gt;I added the children to my view like so&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default function FibonacciView({
  _orientation, children
}: PropsWithChildren&amp;lt;FibonacciViewProps&amp;gt;)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, now I have an issue, I need to add the children to different parts of the view, then I need to use an array of children which thankfully react got us covered on that by using 'Children.toArray(children)` .&lt;/p&gt;

&lt;p&gt;After that, I styled the images to fill the view they’re assigned to, and then onto the assigning children to their views, then recursion which I’m trying not to think about right now. 🙆‍♂️&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8hvvrxv3mx5dgju6mvra.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8hvvrxv3mx5dgju6mvra.png" alt="Views with images" width="800" height="645"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The above are the 4 main orientations, I got distracted by this and didn’t do the flip. I should also have a gap setup for the view and restrict the number of children based on the total view height, but these are problems for another day and hopefully 🙏&amp;nbsp;I’ll be adding them as the days go by.&lt;/p&gt;

&lt;h2&gt;
  
  
  Back to Flip or BackFlip
&lt;/h2&gt;

&lt;p&gt;I’m sorry 🥲&amp;nbsp;&lt;/p&gt;

&lt;h3&gt;
  
  
  Flip horizontal
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fviq0qaj5cjr10sr91q1a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fviq0qaj5cjr10sr91q1a.png" alt="Horizontal view and flip goal" width="800" height="408"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Flip horizontal Reverse
&lt;/h3&gt;

&lt;p&gt;I had to fix the Horizontal reverse as it was actually flip in the original view. To be honest, the code is getting more complicated, but my concern is not the complexity, it’s the readability of it and for that, I’m going to create a new /(Link to section)structure to further modularize the views.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw1leywlfk6060izbihs7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw1leywlfk6060izbihs7.png" alt="Horizontal view and reverseflip goal" width="800" height="408"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F594dsbid7fzb2ssphg5h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F594dsbid7fzb2ssphg5h.png" alt="Horizontal view and reverseflip with images" width="799" height="321"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Flip Vertical
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmftfqu8efu2cyz5rrzl4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmftfqu8efu2cyz5rrzl4.png" alt="Flip vertical" width="800" height="408"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now I’m getting the hang of it, Vertical flip works like a charm.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsyglbo3of4iezz8udtoo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsyglbo3of4iezz8udtoo.png" alt="Flip vertical with images" width="800" height="556"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Flex is acting up
&lt;/h3&gt;

&lt;p&gt;I noticed a weird behavior &lt;/p&gt;

&lt;h3&gt;
  
  
  Flip Vertical Reverse
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi7ioft6iih3eh7oh1cpd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi7ioft6iih3eh7oh1cpd.png" alt="Flip vertical reverse" width="800" height="408"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmtq4tsft6h4c32u4orx1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmtq4tsft6h4c32u4orx1.png" alt="Flip vertical reverse with images" width="800" height="562"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I’m so glad that everything is coming to fruition, yet I still don’t like the way it’s coded, I need to figure out a way to make it more simple to understand and use. &lt;/p&gt;

&lt;h2&gt;
  
  
  Aside
&lt;/h2&gt;

&lt;p&gt;I’m thinking of designating different parts of the view as zones and then making different views then assigning them to the appropriate zone, I still don’t know. Please let me know your thoughts &lt;/p&gt;

&lt;h2&gt;
  
  
  Weird Typescript issue
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
{((orientation === OrientationEnum.horizontal &amp;amp;&amp;amp; flip) ||&lt;br&gt;
        orientation === OrientationEnum.horizontal ||&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  OMGGGG
&lt;/h2&gt;

&lt;p&gt;I just realized that I need to write the component in Javascript.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6bal93sal3bl111muepb.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6bal93sal3bl111muepb.gif" alt="DarthVader noooo" width="200" height="200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Putting it outThere
&lt;/h2&gt;

&lt;p&gt;I asked around to see how to create an npm react component for everyone to use and luckily I got a great answer from one pf the communities about where to look, and it was Vite.&lt;/p&gt;

&lt;p&gt;After some research and checking the reviews I found that the Vite solution might have some issues with SSR (Server Side Rendering) and embedding CSS on the server like in NextJs, now I needed a faster more efficient way. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.notion.so/Using-Tsup-f31bff77fec44ee5b27ab9ecc5c45529?pvs=21" rel="noopener noreferrer"&gt;Using Tsup&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Onto the Recursion
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1p18ugeov4uygn3yt11q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1p18ugeov4uygn3yt11q.png" alt="Recursive View" width="800" height="481"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I figured I had to finish the recursion before I bundle it. &lt;/p&gt;

&lt;p&gt;I’m currently trying to figure out a way that will fix the sizing as I want to dynamically set the size of the fibView and then pass a % size recursively for the views&lt;/p&gt;

&lt;h2&gt;
  
  
  Refactoring...
&lt;/h2&gt;

&lt;p&gt;I had to refactor a couple of states within the fibView:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
const [orientation, setOrientation] = useState&amp;lt;OrientationEnum&amp;gt;(_orientation);&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And now I’m using a prop to set it from the parent to be able to dynamically change it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
const [elementResolution, setElementResolution] = useState&amp;lt;ViewResolution&amp;gt;(&lt;br&gt;
    getViewResolution(orientation, _viewResolution)&lt;br&gt;
  );&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This also was another change for the same reason as it’ll help in the recursive step to be able to dynamically change the size and orientation of the view. Maybe I’ll revert to the original, but these states didn’t make sense as I just set them up and didn’t change them after that.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
export type FibonacciViewProps = {&lt;br&gt;
  orientation: OrientationEnum;&lt;br&gt;
  _flip?: boolean;&lt;br&gt;
  _changeOrientation?: () =&amp;gt; void&lt;br&gt;
  _viewResolution: ViewResolution;&lt;br&gt;
};&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is the updated view properties… for now.&lt;/p&gt;

&lt;h3&gt;
  
  
  Hotfix for height
&lt;/h3&gt;

&lt;p&gt;Height ap&lt;/p&gt;

&lt;h2&gt;
  
  
  Back to the recursion
&lt;/h2&gt;

&lt;p&gt;I’ll check if we have more than 3 views I’ll have to create a child FibView recursively.&lt;br&gt;
So for example If I add 8 views like so&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
&amp;lt;FibView&amp;gt; &lt;br&gt;
    &amp;lt;img src="1.png"&amp;gt;&amp;lt;/img&amp;gt;&lt;br&gt;
    &amp;lt;img src="2.png"&amp;gt;&amp;lt;/img&amp;gt;&lt;br&gt;
    &amp;lt;img src="3.png"&amp;gt;&amp;lt;/img&amp;gt;&lt;br&gt;
    &amp;lt;img src="4.png"&amp;gt;&amp;lt;/img&amp;gt;&lt;br&gt;
    &amp;lt;img src="5.png"&amp;gt;&amp;lt;/img&amp;gt;&lt;br&gt;
    &amp;lt;img src="6.png"&amp;gt;&amp;lt;/img&amp;gt;&lt;br&gt;
    &amp;lt;img src="7.png"&amp;gt;&amp;lt;/img&amp;gt;&lt;br&gt;
    &amp;lt;img src="8.png"&amp;gt;&amp;lt;/img&amp;gt;&lt;br&gt;
&amp;lt;/FibView&amp;gt;&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;2 should be displayed on the biggest views and then the remaining 6 images should be passed to the next FibView that's inside the smallest view which will display 2 images and have another FibView with the rest and so on. &lt;/p&gt;

&lt;p&gt;Now that I’m thinking about it I don’t know if this is the best way to do it&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmqb0qchwiexlr0wy26t5.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmqb0qchwiexlr0wy26t5.jpeg" alt="HMMMMMMMMMM" width="261" height="216"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;HMMMMMMM&lt;/p&gt;

&lt;p&gt;Now that I have gotten myself into this rabbit hole, I need to figure out an algorithm to calculate the next fibView in the recursion. I’ll take the horizontal view as a test case&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuy1tzg09wkvy2rmk58wz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuy1tzg09wkvy2rmk58wz.png" alt="Horizontal Flips" width="800" height="408"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Take a step back (Working out the sizes of the views)
&lt;/h2&gt;

&lt;p&gt;Apparently, a parent’s height needs to be determined in order for the child to use percentages, so now I’ll refactor the code in a way to retrieve the actual height of an element and cascade the effect for all of the children.&lt;/p&gt;

&lt;p&gt;After a lot of refactoring, I managed to make it work somehow. &lt;br&gt;
But now I have a better idea, instead of supplying the width and height ///&lt;/p&gt;

&lt;h2&gt;
  
  
  Finally finished recursion (I think)
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4e61nbfezfohm8c6m23v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4e61nbfezfohm8c6m23v.png" alt="Demo View" width="800" height="669"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs5mbur4vciqrlxw1oqwb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs5mbur4vciqrlxw1oqwb.png" alt="End Result" width="800" height="373"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>typescript</category>
      <category>react</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
